如何从 GWT FileUpload 组件中检索文件? [英] How to retrieve file from GWT FileUpload component?

查看:24
本文介绍了如何从 GWT FileUpload 组件中检索文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 GWT fileUploader 组件上传文件,

I want to upload a file using GWT fileUploader component,

我是这样试的,

FileUpload fileUpload = new FileUpload();
filepload.addChangeHandler(new new ChangeHandler() {
    @Override
    public void onChange(ChangeEvent event) {
         // here i submit the form, and a response is created to client side to display success message.
    } });

  • 好的,到目前为止我可以上传文件,并且我可以从 servlet 发出成功消息.
  • 我是在表单面板的 onSubmitCompleate 事件中处理的,
  • 感谢分配.
  • 让我再问一件事,无论如何我可以在将上传的文件保存到数据库之前显示它吗?
  • 即,实际上我需要提供一个用于上传文件的复合组件和文本区域以告知有关文件的详细信息.
  • 当用户选择要上传的文件时,我想显示上传的文件(以便他可以确保上传正确的文件)
  • 当整个表单提交时,它会被保存到数据库中.
  • 推荐答案

    我猜你想允许用户使用 GWT Fileupload 小部件上传文件,然后不想在服务器端处理它. 您希望在客户端使用字节数组表示.

    I am guessing you want to allow user to upload file using GWT Fileupload widget and then do not wish to process it on server side. You want a byte array representation in client side.

    文件处理的通常步骤浏览器 -> 文件上传对话框 -> 选择文件 -> 将带有文件的表单提交到服务器 -> 在服务器上处理文件 -> 将处理后的文件作为响应(字符串)发送回客户端.

    Usual steps for File Processing Browser -> File Upload Dialog -> Select File -> Submit Form with File to server -> Process File on Server -> Send back processed file to Client as response ( string ).

    如果您想避免上述步骤并在浏览器中处理文件,则在当前的 javascript 中无法执行此操作.Flash、Applet、Silverlight 或 Activex 等并行技术可能会有所帮助.将来要采用的正确方法是使用 HTML5 文件 API.

    If you want to avoid the above steps and process the file in browser there is no way to do it in current javascript. Parallel technologies like Flash, Applet, Silverlight or Activex might help. The correct approach to be pursued in future would be using HTML5 file apis.

    如果您不想使用像 flash/applet 这样的遗留技术,那么可以探索 FileReader 上的 HTML5 api.但是权衡是您需要检查是否跨浏览器支持 api.

    If you do not wish to use legacy technology like flash/applet then HTML5 apis on FileReader can be explored. However tradeoff is you need to check whether api is supported across browser.

    FileReader 包含四个异步读取文件的选项:

    FileReader includes four options for reading a file, asynchronously:

    FileReader.readAsBinaryString(Blob|File) - The result property will contain the file/blob's data as a binary string.
    FileReader.readAsText(Blob|File, opt_encoding) - The result property will contain the file/blob's data as a text string. 
    FileReader.readAsDataURL(Blob|File) - The result property will contain the file/blob's data encoded as a data URL.
    FileReader.readAsArrayBuffer(Blob|File) - The result property will contain the file/blob's data as an ArrayBuffer object.
    

    GWT 包装器示例 -https://github.com/bradrydzewski/gwt-filesystem

    参考 -

    这篇关于如何从 GWT FileUpload 组件中检索文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆