Question

In brief, I am trying to POST the IEnumerable<HttpPostedFileBase> objects received in one controller from a view, to another controller on a "REST" server. I have tried to use HttpWebRequest and StreamWriter to send the objects as serialized JSON, but because the files are large images the Max JSON Length prevents this.

I am currently trying to POST the data using "multipart/form-data", following the example I found here http://www.techcoil.com/blog/uploading-large-http-multipart-request-with-system-net-httpwebrequest-in-c/ but this does not seem very... elegant (no offence to the author of the example). Is there a better way to post the data?

Was it helpful?

Solution

You can't post files through ajax and should not try to post them as JSON. Using JSON might look elegant but it's much more inefficient as any binary data would have to be base64 encoded.

You have to do a regular HTTP post as the article that you linked to.

However, if all your users have a browser that supports HTML5 you can do ajax uploads: How can I upload files asynchronously?

If not, you have to use some sort of flash upload component or use IFRAME:s.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top