1
我使用AFNetworking上传多个文件。 我需要为每个图像发送额外的信息,例如图像宽度/高度。网络多文件上传
我想我只是通过图像循环并发送它们,但AFNetworking并没有完全处理它。
(我怀疑AFNetworking将多个请求合并为一个,覆盖额外的信息)
下面是我的代码。
NSURL *url = [NSURL URLWithString:@URL_BASE];
int count = [imageArray count];
for(int i = 0; i < count; ++i)
{
UIImage* image = [imageArray objectAtIndex:i];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: image.size.width], @"width",
[NSNumber numberWithFloat: image.size.height], @"height",
nil];
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@PATH_ALBUM_IMAGE_UPLOAD parameters:params constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
[formData appendPartWithFileData:imageData name:[NSString stringWithFormat:@"file%d", i] fileName:@"avatar.jpg" mimeyTpe:@"image/jpeg"];
}];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setUploadProgressBlock:^(NSInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
[progressView setProgress: totalBytesWritten*1.0f/totalBytesExpectedToWrite animated: YES];
NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
if(totalBytesWritten >= totalBytesExpectedToWrite)
{
progressView.hidden = YES;
}
}];
[operation start];
}
但如果我使用一个**名称**与多个文件,最后一个将覆盖前者。任何建议? – chenzhongpu