问题描述
使用AWSS3TransferUtility将视频上传到Amazon S3时,我遇到一个奇怪的问题。实际上,我正在以5mb的块上传视频。有时我意识到上传停止随机工作,没有任何错误消息。即使在强行终止应用程序并重新开始上传之后,仍然无法正常工作。它仅在我从手机删除应用程序并重新安装时才有效。 这是我使用AWSS3TransferUtility上传块的代码
// ChunkUploadRequest.com
-(void)registerForUploadProgress{
__weak ChunkUploadRequest *uploadReqObj = self;
NSDictionary *videoInfoDic = _videoDic;
self.progressBlock = ^(AWSS3TransferUtilityTask *task,nsprogress *progress) {
[uploadReqObj updatePogressWithVideoInfo:videoInfoDic didSendData:progress.completedUnitCount totalBytesWritten:progress.completedUnitCount totalBytesExpectedToWrite:0 ignoreUpdateCondition:YES];
};
expression.progressBlock = self.progressBlock;
}
-(void)instantiateAWSS3TransferUtility{
if (transferUtility == nil) {
//transferUtility = [AWSS3TransferUtility S3TransferUtilityForKey:appDelegate.AMAZON_ACCESS_KEY_ID];
transferUtility = [AWSS3TransferUtility defaultS3TransferUtility:^(NSError * _Nullable error) {
NSLog(@"error description: %@",error.description);
}];
[self enumerateUploadSuspended];
}
}
-(void)enumerateUploadSuspended{
__weak ChunkUploadRequest *weakSelf = self;
[transferUtility enumeratetoAssignBlocksForUploadTask:^(AWSS3TransferUtilityUploadTask * _Nonnull uploadTask,AWSS3TransferUtilityProgressBlock _Nullable __autoreleasing * _Nullable uploadProgressBlockReference,AWSS3TransferUtilityUploadCompletionHandlerBlock _Nullable __autoreleasing * _Nullable completionHandlerReference) {
*uploadProgressBlockReference = weakSelf.progressBlock;
*completionHandlerReference = weakSelf.completionHandler;
} downloadTask:nil];
}
-(void)registerForUploadCompleted{
__weak ChunkUploadRequest *weakSelf = self;
self.completionHandler = ^(AWSS3TransferUtilityUploadTask *task,NSError *error) {
if (!error) {
Nsstring *methodName=[[weakSelf requestOptions] valueForKey:kMethodNameKey];
if([methodName isEqualToString:kMethodNameUploadAudioComment] && [self requestStatus] == UploadRequestStatusuploadingAudioComments)
{
Nsstring *managedobjectID = [[weakSelf requestOptions] valueForKey:kManagedobjectIDKey];
if(managedobjectID)
{
[weakSelf audioCommentUploadedWithManagedobjectID:managedobjectID];
}
else
{
[weakSelf uploadAudioComments];
}
}
else{
if([methodName isEqualToString:kMethodNameUploadThumbnail])
{
if([self requestStatus]==UploadRequestStatusuploadingThumbnail)
{
[weakSelf setRequestStatus:UploadRequestStatusThumbnailUploaded];
}
}else{
[weakSelf setRequestStatus:uploadRequestStatusChunkUploadCompleted];
[Utils removeFileAtPath:[weakSelf.requestOptions valueForKey:@"chunkPath"]];
}
[weakSelf startUploadingParts];
}
}
else{
NSLog(@"error %@",error.localizedDescription);
}
};
}
-(void)startVideoUploading {
expression = [AWSS3TransferUtilityUploadExpression new];
expression.progressBlock = self.progressBlock;
if(uploadTask){
[uploadTask cancel];
}
NSURL *chunkFilePathUrl = [NSURL fileURLWithPath:[_requestOptions valueForKey:@"chunkPath"]];
Nsstring *folderName=[_requestOptions objectForKey:kUploadRequestFolderNameKey];
Nsstring *amazonUploadVideoPath = [Nsstring stringWithFormat:@"temp/%@/%@/%@/%@",[_requestOptions objectForKey:@"account_id"],[_requestOptions objectForKey:@"user_id"],folderName,[[_requestOptions valueForKey:@"chunkPath"]lastPathComponent]];
[[transferUtility uploadFile:chunkFilePathUrl
bucket:AMAZON_BUCKET
key:amazonUploadVideoPath
contentType:@"application/octet-stream"
expression:expression
completionHandler:self.completionHandler] continueWithBlock:^id(AWSTask *task) {
if (task.error) {
NSLog(@"Error: %@",task.error);
}
if (task.result) {
uploadTask = task.result;
NSLog(@"%ld",(long)uploadTask.status);
[_requestOptions setobject:uploadTask forKey:kUploadTaskKey];
}
return nil;
}];
}
- (void) startUploading{
#ifdef kWriteLogs
[AppDelegate writeLocationToLogFile:[Nsstring stringWithFormat:@"startUploading: %@",_requestOptions]];
#endif
shouldUpload=YES;
_bytesuploaded=0;
if([self requestType] == UploadRequestTypeVideo)
{
[self setRequestStatus:UploadRequestStatusstarted];
[_requestOptions setValue:kMethodNameUploadVideoClip forKey:kMethodNameKey];
}
_isuploading=YES;
[self startVideoUploading];
if([self requestType] == UploadRequestTypeVideo)
{
appDelegate.shouldUpdateProgress=YES;
[[NSNotificationCenter defaultCenter] postNotificationName:kSibmeVideoUploadStartednotificationKey object:nil userInfo:_requestOptions];
}
}
我正在从ChunkUploadManager类中调用上述类。这是ChunkUploadManager类的调用
- (void) startUploadingNextVideoInQueue
{
#ifdef kWriteLogs
[AppDelegate writeLocationToLogFile:@"startUploadingNextVideoInQueue:"];
#endif
for(ChunkUploadRequest *request in uploadRequestsDictionary.allValues)
{
#ifdef kWriteLogs
[AppDelegate writeLocationToLogFile:[Nsstring stringWithFormat:@"startUploadingNextVideoInQueue request: %@",request.requestOptions]];
#endif
if(request.requestStatus==UploadRequestStatusNotStarted)
{
[request instantiateAWSS3TransferUtility];
[request registerForUploadCompleted];
[request registerForUploadProgress];
[request startUploading];
_isuploading=YES;
break;
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)