If there's a way for the client side GWT code to pre-process a file on the client computer? For example, to calculate a checksum of it before submitting the file to the server.
如果客户端GWT代码有一种方法可以在客户端计算机上预处理文件?例如,在将文件提交到服务器之前计算它的校验和。
4 个解决方案
#1
No it is not possible. The manipulation of the file is done by the browser, not the HTML code.
不,这是不可能的。文件的操作由浏览器完成,而不是HTML代码。
Think about it, GWT is 100% javascript. And javascript has no access whatsoever of the file in your computer. That would be an pretty big security risk! GWT "wraps" the file input box so it can be displayed inside the GWT panel. But once you press the "upload" button, the upload is done by the browser.
想想看,GWT是100%的javascript。并且javascript无法访问您计算机中的任何文件。这将是一个相当大的安全风险! GWT“包装”文件输入框,以便它可以显示在GWT面板内。但是一旦按下“上传”按钮,上传就由浏览器完成。
You could do file manipulation with another technology however. Java applets for example. But that is outside of GWT area...
但是,您可以使用其他技术进行文件操作。例如Java小程序。但那不在GWT区域......
#2
Using GWT, there is no way to read files on the client side yet. However, in HTML5, you can read files without uploading to a server using the "File API".
使用GWT,无法在客户端读取文件。但是,在HTML5中,您可以使用“File API”读取文件而无需上传到服务器。
Links are provided below.
链接如下。
File API tutorial on html5rocks.com
html5rocks.com上的文件API教程
Example of how to use File API in GWT via JSNI
如何通过JSNI在GWT中使用File API的示例
#3
I'm pretty sure that because GWT code compiles to pure JavaScript, there isn't a way without requiring some third-party browser plugin.
我很确定因为GWT代码编译为纯JavaScript,所以没有办法不需要一些第三方浏览器插件。
#4
Do you mean from an <input type="file"...>
file upload field in a form?
你的意思是从表格中的文件上传字段?
The short answer is no-- file uploads are handled by the browser, and are sent directly to the server (as an ENCODING_MULTIPART POST). And security restrictions on JavaScript mean there's no way to workaround that restriction.
简短的回答是否 - 文件上传由浏览器处理,并直接发送到服务器(作为ENCODING_MULTIPART POST)。 JavaScript的安全限制意味着没有办法解决这个限制。
#1
No it is not possible. The manipulation of the file is done by the browser, not the HTML code.
不,这是不可能的。文件的操作由浏览器完成,而不是HTML代码。
Think about it, GWT is 100% javascript. And javascript has no access whatsoever of the file in your computer. That would be an pretty big security risk! GWT "wraps" the file input box so it can be displayed inside the GWT panel. But once you press the "upload" button, the upload is done by the browser.
想想看,GWT是100%的javascript。并且javascript无法访问您计算机中的任何文件。这将是一个相当大的安全风险! GWT“包装”文件输入框,以便它可以显示在GWT面板内。但是一旦按下“上传”按钮,上传就由浏览器完成。
You could do file manipulation with another technology however. Java applets for example. But that is outside of GWT area...
但是,您可以使用其他技术进行文件操作。例如Java小程序。但那不在GWT区域......
#2
Using GWT, there is no way to read files on the client side yet. However, in HTML5, you can read files without uploading to a server using the "File API".
使用GWT,无法在客户端读取文件。但是,在HTML5中,您可以使用“File API”读取文件而无需上传到服务器。
Links are provided below.
链接如下。
File API tutorial on html5rocks.com
html5rocks.com上的文件API教程
Example of how to use File API in GWT via JSNI
如何通过JSNI在GWT中使用File API的示例
#3
I'm pretty sure that because GWT code compiles to pure JavaScript, there isn't a way without requiring some third-party browser plugin.
我很确定因为GWT代码编译为纯JavaScript,所以没有办法不需要一些第三方浏览器插件。
#4
Do you mean from an <input type="file"...>
file upload field in a form?
你的意思是从表格中的文件上传字段?
The short answer is no-- file uploads are handled by the browser, and are sent directly to the server (as an ENCODING_MULTIPART POST). And security restrictions on JavaScript mean there's no way to workaround that restriction.
简短的回答是否 - 文件上传由浏览器处理,并直接发送到服务器(作为ENCODING_MULTIPART POST)。 JavaScript的安全限制意味着没有办法解决这个限制。