PDA

View Full Version : File upload - seeing response JSON



xjscrafter
6 Mar 2014, 10:30 AM
If a file upload using filefield fails, I can see the JSON of the 500 server error in Firebug.

But I do not seem to be able to access that JSON using the action argument of the failure handler.

Is this caused by what is described in the API docs for the hasUpload() method of Ext.form.Basic?

http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.Basic-method-hasUpload

The server response is parsed by the browser to create the document for the IFRAME. If the server is using JSON to send the return object, then the Content-Type (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17) header must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.

So to use the failure JSON in my failure handler, perhaps to display the reason for failure to user, I need to ensure the response has a Content-Type header set to text/html?

Is this specific to ExtJS, or is the same required regardless of the web technology used?

xjscrafter
6 Mar 2014, 12:22 PM
Can anyone provide insight into this?

evant
6 Mar 2014, 1:18 PM
I need to ensure the response has a Content-Type header set to text/html?


Yes.



Is this specific to ExtJS, or is the same required regardless of the web technology used?


No, it's a technique used to upload files in a single page app. Specifying the content type prevents the browser from mangling the response content, as described in the docs. When using an iframe, the only thing you can access is the data in the frame, not the status, nothing else interesting.

xjscrafter
6 Mar 2014, 1:34 PM
Excellent. Thanks Evan.