SweetaAhuja

Untitled

Mar 30th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
  2.     [dic setObject:@"uploadMedia" forKey:@"mode"];
  3.     [dic setObject:@(ShareObj.loginUser.userId) forKey:@"userId"];
  4.     [dic setObject:[self base64forData:mediaData] forKey:@"media"];
  5.     {
  6.         NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer]
  7.                                         multipartFormRequestWithMethod:@"POST"
  8.                                         URLString:@"http://www.myserver.com/webservice.php"
  9.                                         parameters:dic
  10.                                         constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
  11.                                         {
  12.                                             [formData appendPartWithFileURL:[NSURL fileURLWithPath:_mediaPath]
  13.                                                                        name:@"file"
  14.                                                                    fileName:_mediaName
  15.                                                                    mimeType:@"image/jpeg"
  16.                                                                       error:nil];
  17.                                         }
  18.                                         error:nil];
  19.        
  20.         AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
  21.        
  22.         AFJSONResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
  23.        
  24.         [manager setResponseSerializer:responseSerializer];
  25.        
  26.         uploadTask = [manager
  27.                       uploadTaskWithStreamedRequest:request
  28.                       progress:^(NSProgress * _Nonnull uploadProgress) {
  29.                           // This is not called back on the main queue.
  30.                           // You are responsible for dispatching to the main queue for UI updates
  31.                       }
  32.                       completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
  33.                           if (error) {
  34.                               NSLog(@"Error: %@", error);
  35.                           } else {
  36.                               NSLog(@"%@ %@", response, responseObject);
  37.                           }
  38.                       }];
  39.        
  40.         [uploadTask resume];
  41.     }
Add Comment
Please, Sign In to add comment