soknaly

Upload Imag

May 27th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. NSString *imageData = [UIImageJPEGRepresentation(_imageView.image, 60) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
  2.     AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
  3.    
  4.     NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST"
  5.                                      URLString:@"http://www.chamreangkhmer.com/api/uploadImage.php" parameters:@{@"image":imageData,@"name":@"Ae2Bs"}
  6.                      constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
  7.                      } error:nil];
  8.     AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  9.         manager.requestSerializer = [AFHTTPRequestSerializer serializer];
  10.         manager.responseSerializer = [AFHTTPResponseSerializer serializer];
  11.     AFHTTPRequestOperation *operation =
  12.     [manager HTTPRequestOperationWithRequest:request
  13.                                      success:^(AFHTTPRequestOperation *operation, id responseObject) {
  14.                                          NSLog(@"Success %@", operation.responseString);
  15.                                      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
  16.                                          NSLog(@"Failure %@", error.description);
  17.                                      }];
  18.    
  19.     [operation setUploadProgressBlock:^(NSUInteger __unused bytesWritten,
  20.                                         long long totalBytesWritten,
  21.                                         long long totalBytesExpectedToWrite) {
  22.         NSLog(@"Wrote %lld/%lld, %2.lld%%", totalBytesWritten, totalBytesExpectedToWrite,totalBytesWritten*100/totalBytesExpectedToWrite);
  23.     }];
  24.     [operation start];
Advertisement
Add Comment
Please, Sign In to add comment