iOS HTTP multipart-form Streaming Request
Asked Answered
G

1

6

I have to implement a file upload for my app. Files like Assets (which can be Photo or Video) should be uploaded to a web sever using a REST interface.

The upload would use a form data request with custom header attributes.

Problem: Holding large files like Videos in an NSData object can lead to memory issues. This would be the standard approach.

Solution Providing an NSInputStream for the body part of the request - and write data piece by piece to the HTTP Body Stream.

Question Can anyone provide an exmaple of how to use an NSInputStream in combination with a NSURLrequest and NSURLConnection?

I wrapped my head around several incomplete examples -

but I do not know how to deal with the following method

- (NSInputStream *)connection:(NSURLConnection *)connection needNewBodyStream:(NSURLRequest *)request

I don't want to use any third party library.

Girondist answered 17/10, 2013 at 11:36 Comment(0)
E
0

I know you don't want to use any third party library but you could maybe use them as a reference to see how to perform such tasks ?

You could maybe take a look at AFNetworking code to see how Mattt achieved such kind of things.

I'd also suggest using Sessions, that are more documented and robust (if the targeted platform makes it available)

Endorsed answered 24/8, 2015 at 13:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.