Skip to content

Instantly share code, notes, and snippets.

@Broich
Created May 27, 2014 10:10
Show Gist options
  • Save Broich/2fa473e8e58740601c34 to your computer and use it in GitHub Desktop.
Save Broich/2fa473e8e58740601c34 to your computer and use it in GitHub Desktop.
- (void)uploadImageToServer
{
[SVProgressHUD showWithStatus:@"Hochladen" maskType:SVProgressHUDMaskTypeBlack];
NSData *imageToUpload = UIImageJPEGRepresentation(self.croppedImage, 90);
if (!imageToUpload) {
NSLog(@"no data available");
return;
} else {
NSLog(@"%ld", (unsigned long)imageToUpload.length);
}
NSString *urlString = [NSString stringWithFormat:@"%@userImage/upload", BKBaseURL];
NSString *accessToken = @"ZGQzYzEzNWQ0ZmViYmQ2MGVlZjFkNmZkOGExNTI0ODRkMTMwNzdmOWM3MGMwZmQwYTg0NTI2MjU1ZTZlMjA5MA";
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
[manager.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@", accessToken] forHTTPHeaderField:@"Authorization"];
[manager POST:urlString parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:imageToUpload name:@"file" fileName:@"temp.jpg" mimeType:@"image/jpeg"];
}success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"success: %@", responseObject);
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"failure: %@ %@", error, operation.responseString);
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment