简体   繁体   中英

Pass File from Javascript to Java Uploader Applet

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.

我不知道有任何方法可以通过Live Connect将 HTML5创建的ArrayBuffer传递给applet,但是可以(并且可能与跨浏览器更兼容)使用applet(通过JNLP FileOpenService )生成Java文件选择器并从磁盘读取文件。您无需签署applet就可以做到)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM