Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/pyke369/PKMultipartInputStream

an NSInputStream subclass suitable for building multipart/form-data http requests bodies in MacOSX/iOS applications.
https://github.com/pyke369/PKMultipartInputStream

Last synced: about 1 month ago
JSON representation

an NSInputStream subclass suitable for building multipart/form-data http requests bodies in MacOSX/iOS applications.

Awesome Lists containing this project

README

        

######################
PKMultipartInputStream
######################

This NSInputStream subclass is suitable for building multipart/form-data HTTP requests bodies in MacOSX/iOS applications.

=====
Usage
=====

A very simple example is presented below::

PKMultipartInputStream *body = [[PKMultipartInputStream alloc] init];
[body addPartWithName:@"string" string:@"value"];
[body addPartWithName:@"data" data:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"]]];
[body addPartWithName:@"file" path:[[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://site.com/upload.php"]];
[request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", [body boundary]] forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [body length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBodyStream:body];
[request setHTTPMethod:@"POST"];
[[NSURLConnection alloc] initWithRequest:request delegate:self];

An example iOS application is provided along with the class code, please refer to it.