Pass File from Javascript to Java Uploader Applet - java

I've got some Java Applet that I'd like to use to upload file/files to FTP server. Most important method is upload( String ftpServer, String username, String password, String filePath, File sourceFile ).
In JS code I've got stored in array data grabbed from input="file" (user can attach and remove files to different objects he created before, so I have to store this data somewhere).
The problem is that file data is represented by JS File object, when calling upload function is recognized as sun.plugin2.main.client.MessagePassingJSObject (same thing when trying to initialize new java.io.File object).
So questions are:
is there possible to pass somehow object compatible with java.io.File or data about file (I guess only the fullpath) to Java applet ?
if not is there a way to upload from Java code file readed with FileReader to String (for example with .readAsBinaryString method) ?
or if exist any other solution for my problem ?
Edit:
A little more context:
Ftp upload applet is a part of application that uses canvas element (and fabric.js library to be specific). User after adding new elements to canvas area can choose an element and add/assing some files to that element (any image files). Images don't have to be load into canvas area, just their names should appear on a list below canvas when specific element is selected. Of course they can be removed as well.
After user confirms that he finished some data is send (post) to server-side to prepare a control file, than upload this file to ftp server. The only information about selected files required in control file are filenames, so I think it's possible to add file chooser to applet instead JS code, than send that data from applet or pass it to javascript and than send. Before or after posting control file data all files selected by user should be also uploaded to ftp server.
Unfortunately, there is one case when a file have to be loaded into canvas and send to ftp server as well after confirmation - background image file.

I don't know any ways to pass HTML5-created ArrayBuffer to applet via Live Connect, but it is possible (and probably slightly more cross-browser compatible) to spawn Java file chooser and read file from disk, using applet (with JNLP FileOpenService you can do it without signing applet).

Related

How to return a file in web application using Tapestry

I am working on a web application of Data Compression Library. What it does is that it takes an Input file and downloads it on localhost for processing. Downloading is done by using the UploadedFile service of tapestry. After taking this file, a C++ executable is invoked when the form is submitted in the browser. The output of the C++ program is the compressed file that is generated in the same directory as of the downloaded original file. Now what I have to do is, to make the compressed file available for download for the user. I am redirecting the user to another page after the form is filled.
The same goes for decompression, i.e, a form is filled in which file is selected and the file is downloaded to localhost. Decompression is performed via the C++ program and file is generated. User is redirected to another page.
How do I make this file available for download? It should be like a button is displayed and when the user clicks on it, the Save File as pop up should be displayed.
On Java side, just implement an event handler (maybe associated to click events on the download button displayed) returning an instance of the org.apache.tapestry5.StreamResponse interface.
You can find some examples on Tapestry's wiki: https://wiki.apache.org/tapestry/Tapestry5HowToStreamAnExistingBinaryFile.

Where and how does GAE blobstore stores a file (or blob)?

I am new to Google App Engine. I ran (locally) the sample of GAE bolbstore application given in the below link:
https://developers.google.com/appengine/docs/java/blobstore/
It launched a page to choose and submit a file. When I choose a file clicked the submit button:
i) the browser automatically downloads the same file. Why is it again downloading the same file?
ii) it created two files inside the folder 'appengine-generated'. They are:
d06-XwWoSZVw9HRcnLjZiA
local_db.bin
What are these files and where did my file store as blob?
Don't worry too much about what happens locally on the dev server.
i) It's just part of the demo, it serves you back the file you just uploaded because of this line:
res.sendRedirect("/serve?blob-key=" + blobKey.getKeyString());
ii) The first would I guess be the file you've just uploaded, the second would be the local copy of mySQL the dev server is using to emulate the datastore itself. Try comparing sizes to the original file you uploaded?
Once you have stored the file you have to access it via the api's provided, what form and where the file is actually stored no longer matters.

How to save content of applet in jsp to database using servlet programming

I am developing a jsp which contains a applet which captures the image from webcam and shows in same applet.What my need is to save captured image in database through jsp form submit with some other request parametera.Until now i did it by saving the captured image in user directory of local system and then i am reading it form local system directory and then i am using JDBC PreparedStatement.
Now What my need is to to save the Captured Image in Applet with out saving it to local directory.Is it possible to read applet content through the streams?
Thanks in advance.
If I'm reading your question correctly, you're looking to save images in a database instead of the user's local file system. This is certainly possible - though I'd usually recommend storing only metadata about the images in a database, and keeping the images themselves on a file system. In your case, this would probably mean the file system of a server, and not the local desktop running the applet.
If you do want to save the images in the database, JDBC would allow for this. You'll need a database column of a BLOB (binary large object) type, and use the getBlob/setBlob JDBC methods.
Regardless of whether you decide to store the images in a database or the file system on the server, keep in mind that applet security will require your applet to only communicate with the host that the applet is being served from - so you need to host the database or proxy the database connection through the same server that the applet is being served from.

Zip File on a web server to extract in to local machine

We have a web application that allows user to download a zip file from a web server. We just provide dummy iframe source to the full URL of zip file on web server. This approach would allow end user to use browser controls which allows the user to open or save the zip to user's local machine.
We have a requirement that the zip file is automatically extracted and save to a specific location on user's machine. Any thoughts on how this can be achieved?
Thanks.
I highly doubt that you'll be able to do that. The closest you're likely to get is to generate a self-extracting executable file (which would be OS-dependent, of course).
I certainly wouldn't want a zip file to be automatically extracted - and I wouldn't want my browser to be able to force that decision upon me.
Short answer is I don't believe this is possible using the simple URL link you've implemented.
Fundamentally the problem you have is that you have no control over what the user does on their end, since you've ceded control to the browser.
If you do want to do this, then you'll need some client-side code that downloads the zipfile and unzips it.
I suspect Java is the way to go for this - Javascript and Flash both have problems writing files to the local drive. Of course if you want to be Windows only then a COM object could work.
Instead of sending a zip file why don't u instruct the web server to compress all the web traffic and just send the files directly?
See http://articles.sitepoint.com/article/web-output-mod_gzip-apache# for example.

Access Java applet data before it displays on browser

How can I access Java applet data before it displays on my browser?
The applet usually downloads the data from the server using the HTTP protocol, so there is nothing stopping you from using the same URL outside of the applet. The only questions is: What happens with the data? The browser can only download and save it to disk. If you want to process the data, you either need Java (and the applet) or, if the data is really simple, you can do some basic processing in JavaScript.
A third option is to process the data on the server and present it as HTML on a different URL.

Categories