Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using <a href="https://github.com/AFNetworking/AFNetworking" rel="nofollow">AFNetworking</a> this is how I do it:</p> <pre><code>NSMutableDictionary *params = [[NSMutableDictionary alloc]init]; [params setObject:@"myUserName" forKey:@"username"]; [params setObject:@"1234" forKey:@"password"]; [[AFHTTPRequestOperationLogger sharedLogger] startLogging]; NSData *imageData; NSString *urlStr = [NSString stringWithFormat:@"http://www.url.com"]; NSURL *url = [NSURL URLWithString:urlStr]; AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; imageData = UIImageJPEGRepresentation(mediaFile, 0.5); NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:nil parameters:params constructingBodyWithBlock: ^(id &lt;AFMultipartFormData&gt;formData) { [formData appendPartWithFileData:imageData name:@"mediaFile" fileName:@"picture.png" mimeType:@"image/png"]; }]; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"File was uploaded" message:@"" delegate:self cancelButtonTitle:@"Close" otherButtonTitles: nil]; [alert show]; } failure:^(NSURLRequest *request , NSURLResponse *response , NSError *error , id JSON) { NSLog(@"request: %@",request); NSLog(@"Failed: %@",[error localizedDescription]); }]; [operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) { NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite); }]; [httpClient enqueueHTTPRequestOperation:operation]; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload