문제

I need to send large amounts of data (image files) by POST in a WebView, so I'm using NSMutableURLRequest with setHTTPBody:.

Problem: if the data size is more than about 3MB, the app suddenly starts eating up huge amounts of memory and gets dog slow with all the paging.

I've tried changing this:

[request setHTTPBody:[NSData dataWithBytes:post.Get() length:post.Size()]];

..to this:

[request setHTTPBodyStream:[NSInputStream inputStreamWithData:
    [NSData dataWithBytes:post.Get() length:post.Size()]]];

..but then nothing seems to happen and the request just times out. I get none of the normal callbacks (like WebViewProgressEstimateChangedNotification) and the data doesn't seem to get set.

So, how do I (a) make the NSData approach not be a memory hog or (b) make the stream approach work (assuming it's a good workaround)?

도움이 되었습니까?

해결책

I ended up solving it by using NSURLConnection to do the upload manually, and then feeding the result into the WebView. As a bonus, I get much better upload progress updates this way.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top