我正在使用 ASIFormDataRequest 进行上传和下载。下载进度非常准确,下载完成就完成了,但上传进度从0快速跳到1,即使上传还没有完成。下面是上传请求和下载请求
上传请求:
uploadRequest = [[ASIFormDataRequest alloc]initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/ImageBUP.aspx",ZsafeapiURL]] :@"POST"];
[uploadRequest setTag:i];
[uploadRequest setDelegate:self];
[uploadRequest setPostFormat:ASIMultipartFormDataPostFormat];
[uploadRequest setUploadProgressDelegate:[self.progressBarArray objectAtIndex:i]];
[uploadRequest setShowAccurateProgress:YES];
[uploadRequest setData:[[self.dataToUpload objectAtIndex:i]valueForKey:@"data"] forKey:nil] ;
[uploadRequest addRequestHeader:@"UserID" value:[[NSUserDefaults standardUserDefaults] objectForKey:@"userID"]];
[uploadRequest addRequestHeader:@"Handsettype" value:@"3"];
[uploadRequest addRequestHeader:@"ImageName" value:imageName];
[uploadRequest addRequestHeader:@"ImagePath" value:@"0"];
[uploadRequest addRequestHeader:@"Desc" value:[[NSUserDefaults standardUserDefaults] objectForKey:@"platform"]];
[uploadRequest addRequestHeader:@"Extension" value:[[self.dataToUpload objectAtIndex:i]valueForKey:@"extension"]];
[uploadRequest addRequestHeader:@"Size" value:[[self.dataToUpload objectAtIndex:i]valueForKey:@"sizeInByte"]];
[uploadRequest setShouldContinueWhenAppEntersBackground:YES];
[uploadRequest setTimeOutSeconds:500];
[myQueue addOperation:uploadRequest];
Download request:
NSString *videoURL=[[self.dataToUpload objectAtIndex:i]valueForKey:@"videoURL"];
NSString *videoOriginalName=[[self.dataToUpload objectAtIndex:i]valueForKey:@"name"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *folderPath = [documentsDirectory stringByAppendingPathComponent:@"/Videos"];
if (![[NSFileManager defaultManager] fileExistsAtPath:folderPath])
[[NSFileManager defaultManager] createDirectoryAtPath:folderPath withIntermediateDirectories:NO attributes:nil error:nil];
NSString *videoPathInApp=[folderPath stringByAppendingPathComponent:videoOriginalName];
downloadRequest = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:videoURL] :@"GET"];
[downloadRequest setDelegate:self];
[downloadRequest setDownloadDestinationPath:videoPathInApp];
[downloadRequest setDownloadProgressDelegate:[self.progressBarArray objectAtIndex:i]];
[downloadRequest setTag:i];
[downloadRequest setShowAccurateProgress:YES];
[myQueue addOperation:downloadRequest];
我错过了什么吗?