3

我正在使用 AngularJS 应用程序中的这个插件将文件上传到 REST API。当 'fileuploaddone' 事件触发几秒钟后,我从 Internet Explorer 收到一条黄色通知:你想保存\打开

附上截图。

在此处输入图像描述

4

2 回答 2

4

基于 iframe 的上传要求 JSON 响应的内容类型为 text/plain 或 text/html - 如果 iframe 响应设置为 application/json,它们将显示不需要的下载对话框。

来源:https ://github.com/blueimp/jQuery-File-Upload/wiki/Setup#content-type-negotiation

您需要按照上面链接中的说明设置正确的 Content-Type。

于 2013-11-05T12:31:23.230 回答
-1

Blueimp jQuery 文件上传设置以支持现代浏览器以及 IE9(在 IE9 和 Chrome 39 上测试)

注意:我在服务器端使用 JAVA、Spring 3

index.html 文件

<!doctype html>
<!--[if lt IE 9]>      <html class="lt-ie9"> <![endif]-->
<!--[if IE 9]>         <html class="ie9"> <![endif]-->
<!--[if gt IE 9]><!--> <html>         <!--<![endif]-->

     <head>....</head>
     <body>....</body>
</html>

test.js 文件

var options = {
    url: 'api/test/fileupload',
    maxFileSize: 10000000,
    formData: {
        id: 1
    }
};

if ($('html').hasClass('ie9') || $('html').hasClass('lt-ie9')) {
    options.forceIframeTransport = true;
} else {
    options.dataType = 'json';
}

$('#fileUploadInput').fileupload(options);

测试.java 文件

@POST
@Path("/api/test/fileupload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ "text/plain" })
public Response uploadFile(
        @Context HttpServletResponse response,
        @Context HttpServletRequest request,
        @FormDataParam("id") Long id,
        @FormDataParam("files[]") FormDataContentDisposition fileDetail,
        @FormDataParam("files[]") InputStream uploadedInputStream) {
    String header = request.getHeader("accept");
    String returnContentType = MediaType.APPLICATION_XML;
    VEWTestAttachment attObj = testMgr.saveAttachment(id,fileDetail,uploadedInputStream);
    if(header.indexOf(MediaType.APPLICATION_JSON) >= 0){
        returnContentType = MediaType.APPLICATION_JSON;
    }
    response.setContentType(returnContentType);
    return Response
            .ok(attObj,returnContentType)
            .build();
}
于 2014-12-04T07:01:53.790 回答