解析图像抛出 AFNetworking
parse image threw AFNetworking
我需要将图像传递到网络服务中。我正在使用 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)
谁能告诉我这段代码有什么问题?谢谢
用于从 pickercontroller 获取图像并将图像上传到服务器。
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);
}];
希望这能解决您的问题。
我需要将图像传递到网络服务中。我正在使用 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)
谁能告诉我这段代码有什么问题?谢谢
用于从 pickercontroller 获取图像并将图像上传到服务器。
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);
}];
希望这能解决您的问题。