简体   繁体   English

将文件从Javascript传递到Java Uploader Applet

[英]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. 我有一些Java Applet,可以用来将文件上传到FTP服务器。 Most important method is upload( String ftpServer, String username, String password, String filePath, File sourceFile ). 最重要的方法是upload(String ftpServer,String用户名,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). 在JS代码中,我存储在从input =“ file”抓取的数组数据中(用户可以将文件附加和删除到他之前创建的不同对象上,因此我必须将此数据存储在某个地方)。

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). 问题在于,当调用上载函数时,文件数据由JS File对象表示,被识别为sun.plugin2.main.client.MessagePassingJSObject(尝试初始化新的java.io.File对象时也是如此)。

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 ? 因此,问题是:是否可以将与java.io.File或与文件有关的数据(我猜只是全路径)兼容的对象以某种方式传递给Java applet?

if not is there a way to upload from Java code file readed with FileReader to String (for example with .readAsBinaryString method) ? 是否没有办法从FileReader读取的Java代码文件上载到String(例如,使用.readAsBinaryString方法)?

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). ftp上传小程序是使用canvas元素(具体来说是fabric.js库)的应用程序的一部分。 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. 用户确认完成后,一些数据被发送(发布)到服务器端以准备一个控制文件,然后将该文件上传到ftp服务器。 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. 关于控制文件中所需的选定文件的唯一信息是文件名,因此我认为有可能将文件选择器添加到applet而不是JS代码中,而不是从applet发送该数据或将其传递给javascript,然后发送。 Before or after posting control file data all files selected by user should be also uploaded to ftp server. 在发布控制文件数据之前或之后,用户选择的所有文件也应上传到ftp服务器。

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. 不幸的是,在某些情况下,必须将文件加载到画布中并在确认后也发送到ftp服务器-背景图像文件。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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