【问题标题】:Problem uploading a file with ajax in appengine在 appengine 中使用 ajax 上传文件时出现问题
【发布时间】:2011-02-07 10:23:09
【问题描述】:

我需要在 Google AppEngine 应用程序中使用 Ajax 将文件的内容发送到 Spring webService。所以我使用了jquery ajaxFileUpload plugin

<form id="load_form" action="" enctype="multipart/form-data">       
    <input name="file" type="file" id="upload_files" value="Browse"/>
    <input type="button"" id="upload_file" value="Load file"/>
</form>

javascript 看起来像这样:

$("#upload_file").click(function(){

        $.ajaxFileUpload
        (
            {
                url: '/myproject/uploadFile.json',
                secureuri: false,
                fileElementId: 'upload_files',
                dataType: 'json',
                success: function (data, status) {
                    alert("OK");
                },
                error: function (data, status, e) {
                    alert("Error");
                }
            }
        );

        return false;
    });

在控制器中:

@RequestMapping(value="/uploadFile.json", method=RequestMethod.POST)
public Map<String, Object> readFile(
        @RequestParam(value = "file", required=false) MultipartFile file,
        Model model) throws Exception{
    ...
}

我遇到的问题是我没有在文件参数中接收文件内容(它始终为空)并且使用 firebug 我可以看到我在一个名为“文件”的参数中发送文件的内容”。但是尽管调用了此方法,但我没有收到它们(我在其中有一个断点,并且它在其中停止)。如果我从文件参数中删除 required=false ,则会给出 400 错误,因此它看起来找不到文件参数。

我正在使用 Spring 3.0.4。

知道会发生什么吗?

谢谢。

【问题讨论】:

    标签: java ajax spring google-app-engine spring-mvc


    【解决方案1】:

    如果你在这种情况下是结果导向的,你可以使用custom servlet

    【讨论】:

      猜你喜欢
      • 2014-06-02
      • 2020-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多