我对 iOS 完全陌生。我想使用将图像上传到我的服务器AF网络。
我尝试了但仍然没有完成。请帮助我,提前致谢
尝试一下它对我有用
-(void) uplodeImages{
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:@"url where to upload images"]];
NSData *imageData = UIImagePNGRepresentation([UIImage imageNamed:@"cat1.png"]);
NSDictionary *parameters = @{@"username": @"", @"password" : @""};
AFHTTPRequestOperation *op = [manager POST:@"cat1.png" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
//do not put image inside parameters dictionary as I did, but append it!
[formData appendPartWithFileData:imageData name:@"userfile" fileName:@"cat1.png" mimeType:@"image/png"];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success: %@ ***** %@", operation.responseString, responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@ ***** %@", operation.responseString, error);
}];
[op start];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)