我要求将图像传递到Web服务中。我正在使用AFNetworking。到目前为止,我的代码如下所示。
NSData *imageData = UIImageJPEGRepresentation(_imgA.image, 0.5);
params = @{@"category":self.displayDept.text,
@"location": locationAdress.text,
@"topic":self.topic.text,
@"image":imageData,
@"email":[NSString stringWithFormat:@"%@",useEmail]
};
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager POST:@"webservice....."
parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFormData:imageData name:@"imageData"];
} success:^(NSURLSessionTask *task, id responseObject)
有人能说出这段代码有什么问题吗?感谢
答案 0 :(得分:0)
For getting image from pickercontroller and upload image to server.
UIImage *img = [info valueForKey:UIImagePickerControllerOriginalImage];
NSData *imgData = UIImageJPEGRepresentation(image, 0.5);
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = @{@"foo": @"bar"};
[manager POST:@"<json link>" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFormData:imgData name:@"image"];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
Hope this solved your problem.