【发布时间】:2013-12-26 06:58:50
【问题描述】:
我正在一个应用程序中工作,我需要将 3 张图像发送到 Web 服务器。我不知道快速有效的完美方法。
我有 3 个UIImageView 从相机或相册捕获图像数据。下面,我使用AFNetworking 将 1 张图片发送到 Web 服务器。
NSString *imgPath = [[NSBundle mainBundle]pathForResource:@"Default" ofType:@"png"];
NSData *imgData = UIImagePNGRepresentation([UIImage imageWithContentsOfFile:imgPath]);
NSData *imagVIewData = UIImageJPEGRepresentation(imageView1.image,90);
if (imagVIewData) {
AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://myurl.com/xxx.php]];
NSMutableURLRequest *myRequest = [client multipartFormRequestWithMethod:@"POST" path:Nil parameters:Nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:imagVIewData name:@"file_upload" fileName:@"123.jpg" mimeType:@"images/jpeg"];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:myRequest];
[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
NSLog(@"Sent %lld of %lld bytes",totalBytesWritten,totalBytesExpectedToWrite);
}];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"upload complete");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@",operation.responseString);
}];
NSOperationQueue *queue = [[NSOperationQueue alloc]init];
[queue addOperation:operation];
}
}
我需要有人建议从 3 个 UIImageViews 发送 3 个不同的图像。这个程序是否可行,还是我需要通过不同的方法工作?
有什么想法吗?
【问题讨论】:
标签: ios objective-c uiimageview afnetworking