internet-explorer - 使用不同浏览器在 Play Framework 中上传文件

标签 internet-explorer firefox google-chrome file-upload playframework

我正在使用 playframework 来构建一个网站。而且我还使用了一个名为 xheditor 的富编辑器.

Xheditor 支持ajax-fileuploading,它需要服务器端有一个 Action 接受包含上传文件的“filedata”参数。

所以我写了一个上传 Action :

public class Application extends Controller {
    public static void upload(File filedata) { 
        // the filedata should not be null
        renderText("{'err':'', 'msg':{'ur':'/uploaded/xxx.zip'}}"); 
    } 
}

它在 IE6 中工作正常,文件数据不为空并且包含正确的数据。但是,如果我使用 chrome 或 firefox,文件数据是 !!

我使用firebug来监控firebug提交的内容,发现它提交了这样一个header:
content-disposition
attachment; name="filedata"; filename="051111twdns.zip"

我认为 play 没有正确处理这种情况,所以参数“filedata”为空。

为了使用 chrome 和 firefox,我修改了该操作:
public class Application extends Controller {
    public static void upload(File filedata) { 
        if(filedata!=null) {
            // ok, it's IE6
            renderText("{'err':'', 'msg':{'ur':'/uploaded/xxx.zip'}}"); 
        } else {
            // it's chrome or firefox, the data is in request.body
            File targetFile = new File("upload/test.zip");
            IOUtils.copy(request.body, new FileOutputStream(targetFile));
        }
    } 
}

现在可以在 IE6、chrome 和 firefox 中使用,但是 , 仅当上传文件很小时。例如。小于4K。如果它有点大,例如12K,方法“IOUtils.copy”会报“Read Error!”,即使是下面的代码也会报这样的错误:
request.body.available()
request.body.read()
request.body.read(bytes)

最佳答案

尝试将您的网站与文件上传器集成,其中包含大量不同语言的文档/示例
www.uploadify.com/

关于internet-explorer - 使用不同浏览器在 Play Framework 中上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3863443/

相关文章:

javascript - 在 IE 中选择禁用的单选按钮时如何保持单选按钮被选中?

javascript - 使用 JavaScript 动态添加按钮

css - 如何在 Firefox 和 Opera 中缩放 HTML 元素?

firefox - Firefox 在每个 document.write() 之后创建新历史记录的解决方法

Html5 视频轨道数据uri

internet-explorer - IE、P3P、IFrame 和阻止的 cookie(在页面主机页面请求个人信息之前有效)

javascript - 如何在 Windows Phone 7 上调试 Internet Explorer?

javascript - 如何让这些 Sprite 动画在 Firefox 中工作

css - Chrome CSS 位置 :fixed

Android 6.0 Chrome 上传文件而不是 Firefox