Created
May 27, 2014 10:10
-
-
Save Broich/2fa473e8e58740601c34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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