0

我正在开发一个聊天应用程序,我可以在其中传输视频/音频/图像等媒体。

当使用下面的代码片段完成传输时,在 Wifi 上传输很流畅,但在移动到 3G 网络时非常慢。

另一个问题是当我进入后台时,AWS SDK 暂停传输并在我进入前台时恢复。

1) 我尝试更改 AWS 区域时如何才能快速进行传输,但仍然没有成功。2) 与使用的 AWS S3 传输管理器相比,还使用 ​​S3Background 传输示例,但是当我按下主页按钮时下载暂停。

下面是我截取的代码。

//上传函数

AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];

AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
uploadRequest.bucket = S3BucketName;

User *userMO = .....my user details 

NSString *fileName = [[filePath componentsSeparatedByString:@"/"] lastObject];

uploadRequest.key = [userMO.user_pool_id stringByAppendingPathComponent:fileName];

NSURL *uploadFileURL = [NSURL fileURLWithPath:filePath];

uploadRequest.body = uploadFileURL;

uploadRequest.expires = [NSDate dateWithTimeIntervalSinceNow:3600];


NSString *fileContentTypeStr = @"image/jpg";

if ([FileManager isVideoFile:fileName]) {
    //        fileContentTypeStr = [NSString stringWithFormat:@"video/%@",[[fileName pathExtension] lowercaseString]];
    fileContentTypeStr = [NSString stringWithFormat:@"video/quicktime"];
}
else if ([FileManager isImageFile:fileName]) {
    fileContentTypeStr = [NSString stringWithFormat:@"image/%@",[[fileName pathExtension] lowercaseString]];
}
else if ([FileManager isAudioFile:fileName]) {
    fileContentTypeStr = [NSString stringWithFormat:@"audio/%@",[[fileName pathExtension] lowercaseString]];
}

uploadRequest.contentType = fileContentTypeStr;

[[transferManager upload:uploadRequest] continueWithBlock:^id(AWSTask *task) {

    if (task.error) {

        if ([task.error.domain isEqualToString:AWSS3TransferManagerErrorDomain]) {
            switch (task.error.code) {
                case AWSS3TransferManagerErrorCancelled:
                {
                        //updating ui to notify cancel

                }
                    break;
                case AWSS3TransferManagerErrorPaused:
                {
                        //updating ui to notify paused
                }
                    break;

                default:
                {
                    NSLog(@"Upload task failed: %@",[task.error localizedDescription]);
                        //updating ui to notify failed
                }
                    break;
            }
        } else {
            NSLog(@"Upload task failed: %@",[task.error localizedDescription]);
                        //updating ui to notify failed

        }
    }

    if (task.result)
    {
                        //updating ui to notify finished
    }
 return nil;
 }];


if(uploadRequest.state == AWSS3TransferManagerRequestStateRunning)
{
                        //updating ui to notify progress
}

//Add the request to the current upload cache handler entry as handle

任何机构都有任何建议并面临类似的问题。

4

1 回答 1

0

使用 AWS 后台传输而不是 AWS 传输管理器来使用支持的后台模式传输。

于 2016-03-30T13:36:16.320 回答