我想上传多个图像。使用委托didSendBodyData.But上传单个图像并获取进度值,而我在那时上传多个图像获取所有图像的进度值。我想逐个获取上传所有进度值images。我上传图片的代码:
NSString *urlString = @"/new_api/temp-album1.php?type=image";
NSURL *theURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",baseURL,urlString]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:theURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:200.0];
[request setHTTPMethod:@"POST"];
NSString *boundary = @"YOUR_BOUNDARY_STRING";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];
NSMutableData *body = [NSMutableData data];
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
//Sending Image :
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"image\"; filename=\"%@er.jpg\"\r\n", imageName] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
connectionManager *connMang = [[connectionManager alloc] init];
[connMang startConnectionWithRequest:request handler:handler errorHandler:errorHandler];`
答案 0 :(得分:0)
这是一个简单的解决方案,可能对您有用。请尝试理解后续步骤
1)获取要上传的图像数量。假设您有x = 10图像
2)因此,您可以将进度条划分为10个相等的部分
3)维护一个用于图像编号
的变量4)假设当前上传的图像4,您可以按照以下方式计算进度
(image number*Progress_of_image)/x