PDA

View Full Version : Uploading a file response issue



Chods
10 Aug 2010, 6:02 AM
I am trying to upload a file to the server using Ext. The file uploads fine but I am having trouble with the response. It does not seem to matter how i set the response it always seems to get returned as xml if i use a .net web service. I understand this maybe a limitation of a web service as it requires a json request in order to respond with a json response for some reason.

However I then went on to try and do the same with a generic handler (.ashx) file and yet again it does not seem to matter how i set the response it is not handled correctly. In firefox it tries to open the response as a file. My json string is inside this file. In IE i get an error.

Has anyone come across this. I have copied my code from http://dev.sencha.com/deploy/dev/examples/form/file-upload.html

arthurakay
10 Aug 2010, 11:28 AM
What is the "Content-Type" of your response? I think it needs to be application/json in order to prevent the download popup.

Chods
11 Aug 2010, 1:16 AM
Thanks for your reply.

yes it is application/json.

Its incredibly weird. Uploading files to the server is something I have implemented many times in my life. I cannot understand why this is happening at all.

Condor
11 Aug 2010, 1:21 AM
The response header should have Content-disposition:inline to avoid a 'Save as' dialog.

Also, specifically for a file upload the response should be Content-type:text/html.

Chods
11 Aug 2010, 5:45 AM
The response header should have Content-disposition:inline to avoid a 'Save as' dialog.

Also, specifically for a file upload the response should be Content-type:text/html.

Thanks condor but this does not work in my situation. Out of interest, why should a file upload have a response type of text/html.

Condor
11 Aug 2010, 6:20 AM
Ext can't use XmlHttpRequest for file uploads, so it uses a form submit to a hidden IFRAME.

The result is loaded in the IFRAME, so it must be valid HTML.

Example return values:

<html>
<body>
{
"success": true,
"message": "Text needs to be HTML escaped, e.g. &amp; &lt; &gt;"
}
</body>
</html>

<html>
<body>
<textarea>
{
"success": true,
"message": "Text in a TEXTAREA doesn't need to be HTML escaped, e.g. & < >"
}
</textarea>
</body>
</html>