第 1 步:我在这里创建请求
NSMutableURLRequest *request1 = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST"
URLString:[NSString stringWithFormat:@"%@%@", API_MAIN_URL, IMAGE_UPLOAD]
parameters:param constructingBodyWithBlock:^(id formData) {
[formData appendPartWithFileURL:[NSURL fileURLWithPath:strImagePath]
name:@"sendimage"
fileName:[strImagePath lastPathComponent]
mimeType:@"image/png"
error:nil];
} error:nil];
[request1 setValue:authToken forHTTPHeaderField:@"Authorization"];
第2步:在这里我在给定位置创建流
[[AFHTTPRequestSerializer serializer] requestWithMultipartFormRequest:request1
writingStreamContentsToFile:[NSURL fileURLWithPath:[strImagePath stringByDeletingPathExtension]]
completionHandler:^(NSError *error){
第3步:在这里我正在创建上传任务。
///here is file
NSProgress *progress = nil;
NSURLSessionUploadTask *uploadTask = [self.manager uploadTaskWithRequest:request1
fromFile:[NSURL fileURLWithPath:strImagePath]
progress:&progress
completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
NSLog(@"response : %@\n\n responseObject : %@\n\n error : %@", response, responseObject, error);
}];
[uploadTask resume];
}
}];
}
我的问题是在应用程序进入后台模式之前,我想HTTPBody
使用步骤:1 和步骤:2 在给定位置写入所有请求(HTTPStream),并NSArray
在写入所有HTTPStream
文件(在应用程序前台中)意味着之后将所有请求保存到同时我将显示图像准备上传。
然后我将在 Step3 的帮助下开始创建后台任务:将请求传递给我已存储到NSArray
. 使用这种方法,我无法上传图片。
但是如果我将所有步骤一个一个地调用,那么它将把图像上传到服务器上,但是通过这种方法,我的应用程序应该在前台进行创建请求,因为我们需要HTTPBody
在给定位置编写。
请帮我解决这个问题,我从上周开始就被困在这个问题上。我的应用程序需要通过服务器上传超过 500 张图片。