jfeldstein/jQuery.AjaxFileUpload.js

on return the json, the browser ask to choose a program to open the file...

Closed this issue · 4 comments

when I subimit a file the browser ask me to download the response... =P

Sounds like an issue with your server sending back the wrong headers. (There's a header that forces download.)

What happens if you browse to the endpoint that you're using to process the upload?

Just wanted to comment on your plugin. I integrated your plugin in my application, and it worked flawlessly in chrome & firefox. However, IE browser was forcing a dialog to choose a program to open the file. The contents of the file to download always held my returned JSON object.

I was using Spring 3.0 and within my controller class I had to switch the headers from "application/json" to "text/html" like so:

public ResponseEntity<String> uploadMyFile(@ModelAttribute("object") FileUploadBean cmd) {

    MyJson result = myService.doSomething(cmd);


    Gson gson = new Gson();
    String json = gson.toJson(result);

    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(MediaType.TEXT_HTML);
    return new ResponseEntity<String>(json, responseHeaders, HttpStatus.CREATED);

}

Thus, switching the type of header returned solved my issue. Not sure why, but Chrome and Firefox had no issue. Hope this helps someone else.

@dtarkenton different browsers handle different mime types in there own
way, but this is an issue with the what type your server is sending - not
with the script.

The fix you implemented is the correct fix.

~J

(via phone)
On Sep 28, 2012 3:17 PM, "dtarkenton" notifications@github.com wrote:

Just wanted to comment on your plugin. I integrated your plugin in my
application, and it worked flawlessly in chrome & firefox. However, IE
browser was forcing a dialog to choose a program to open the file. The
contents of the file to download always held my returned JSON object.

I was using Spring 3.0 and within my controller class I had to switch the
headers from "application/json" to "text/html" like so:

public ResponseEntity uploadMyFile(@ModelAttribute("object") FileUploadBean cmd) {

MyJson result = myService.doSomething(cmd);


Gson gson = new Gson();
String json = gson.toJson(result);

HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.TEXT_HTML);
return new ResponseEntity<String>(json, responseHeaders, HttpStatus.CREATED);

}

Thus, switching the type of header returned solved my issue. Not sure why,
but Chrome and Firefox had no issue. Hope this helps someone else.


Reply to this email directly or view it on GitHubhttps://github.com//issues/5#issuecomment-8991918.

Agreed. I simply felt the header information may help someone else who used your plugin. Unfortunately, many apps still have to support IE.