AFNetworking/AFNetworking — pull request #368 by mattt (2012-06-05 16:14:56+00:00)
Title: Multipart Upload Streaming

This was something I tried (unsuccessfully) to implement back in #177, and seem to finally have gotten working this time around.

I successfully tested this on the Mac, but I'd like some more testing and feedback—especially on the iPhone, which benefits the most from this approach.

## Why is this cool?

Normally, when `AFHTTPClient -multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:` is called, the URL request is built up in memory. If you're trying to upload anything significant (even a several-megabyte image), this can have a serious performance impact, to the point of crashing the app.

By writing the form request to a temp file on disk, we not only avoid the memory overhead, but get HTTP body streaming as well. Perhaps the best part is that this implementation doesn't change the public API at all.

I haven't noticed this myself, but the only way this could negatively affect performance compared to the current approach would be for small multipart requests that could be stored in-memory. I don't think this will be as much of an issue, and is worth the tradeoff for massively-improved performance on large requests.

## What Can I Do To Help?

Again, I'd love to get confirmation that this approach is stable on iOS apps. Any feedback on the implementation would be appreciated as well.