(This is really a double-whammy in terms of questions, since there really is two serperate questions, but they kinda belong together.)
First Question:
How would I go about uploading a file (I have an NSData object containing the file's contents already) using POST, while displaying the upload progress in an NSProgressIndicator
? Much like one can do bytesReceived in NSURLDownload
, but this time tracking how many bytes have already been sent using POST.
Second Question:
While I have this NSData
Array, I shall be using the code below to send the NSData
array. Here, it confuses me how I would tell it that for example, the POST value 'file' is the NSData
object. NSDictionary
would probably do the job here, but I don't have access to my computer and the lovely Apple Docs right now.:
NSMutableURLRequest* post = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:@"http://yourdomain.com/post.php"]];
[post setHTTPMethod: @"POST"];
[post setHTTPBody:myFileNSData];
NSURLResponse* response;
NSError* error;
NSData* result = [NSURLConnection sendSynchronousRequest:post returningResponse:&response error:&error];
NSLog(@"%@", [[[NSString alloc] initWithData:result encoding:NSASCIIStringEncoding] autorelease]);
I'd appreciate any help.