首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >亚马逊s3传输实用程序不能在后台运行

亚马逊s3传输实用程序不能在后台运行
EN

Stack Overflow用户
提问于 2019-01-01 18:06:00
回答 2查看 925关注 0票数 0

我必须上传一个像4 4gb以上的大文件到亚马逊s3。amazon sdk提供了从s3上传和下载的两个选项。一个是awss3transfermanager,另一个是awss3transferutility。我实际上想使用awss3transferutility,因为我想让应用程序在后台继续上传。awss3transferutility有两个函数uploadFile和其他uploadFileUsingMultiPart。uploadFile函数实际上在后台工作,但上传在网络更改或丢弃时从0开始。出于这个原因,我目前使用的是uploadFileUsingMultiPart函数,这样在网络失败时,上传就不会从0重新开始。但是这个uploadFileUsingMultiPart函数不会在后台继续上传。在他们的最新版本中,他们在awstransferutility实用程序中引入了这个uploadFileUsingMultiPart函数。所以我预计上传会在后台继续,但不会在后台继续。我只想问是sdk相关的bug,还是我做错了什么

这就是我现在使用的代码

//在应用代理中

代码语言:javascript
复制
- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler {
    [AWSS3TransferUtility interceptApplication:application
           handleEventsForBackgroundURLSession:identifier
                             completionHandler:completionHandler];
}

//在ViewController中

代码语言:javascript
复制
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(reachabilityChanged:)
                                                 name:kReachabilityChangedNotification
                                               object:nil];

    __weak typeof(self) weakSelf = self;
    expression = [AWSS3TransferUtilityMultiPartUploadExpression new];
    expression.progressBlock = ^(AWSS3TransferUtilityMultiPartUploadTask *  task, NSProgress *  progress) {
       typeof(self) newWeakSelf = weakSelf;

       dispatch_async(dispatch_get_main_queue(), ^{
           // Do something e.g. Alert a user for transfer completion.

           NSLog(@"progress value %f",progress.fractionCompleted);
           // On failed uploads, `error` contains the error object.
           newWeakSelf->progressView.progress = progress.fractionCompleted;
       });
   };

   completionHandler = ^(AWSS3TransferUtilityMultiPartUploadTask *task, NSError *error) {
       dispatch_async(dispatch_get_main_queue(), ^{
           NSLog(@"uploading completed ");
       });
   };


   AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1 identityPoolId:@"us-west-1:7a24b199-e4b2-4657-9627-sdfs4ssdff"];
   AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider];
   // AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration;

   AWSS3TransferUtilityConfiguration *tfConfig = [AWSS3TransferUtilityConfiguration new];
   tfConfig.retryLimit = 5;
   tfConfig.multiPartConcurrencyLimit = [NSNumber numberWithInteger:3];
   [AWSS3TransferUtility registerS3TransferUtilityWithConfiguration:configuration transferUtilityConfiguration:tfConfig forKey:@"transfer-utility-with-advanced-options"];

   transferUtility = [AWSS3TransferUtility S3TransferUtilityForKey:@"transfer-utility-with-advanced-options"];
}

-(void)startUploading {
    NSString *filePath =   [[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp4"];
    NSURL *fileURL =  [NSURL fileURLWithPath:filePath];
    NSString *fileContentTypeStr = @"video/mp4";

    //  NSData *data = [NSData dataWithContentsOfURL:fileURL];
    //  AWSTask *task = [transferUtility uploadDataUsingMultiPart:data bucket:@"sibme-development" key:@"temp/testfilenew/testfile1.mp4" contentType:fileContentTypeStr expression:expression completionHandler:completionHandler ];

    AWSTask *task = [transferUtility uploadFileUsingMultiPart:fileURL bucket:@"development" key:@"temp/testfilenew/testfile.mp4" contentType:fileContentTypeStr expression:expression completionHandler:completionHandler];

    [task continueWithBlock:^id _Nullable(AWSTask * _Nonnull t) {
        if (t.result) {
          self->uplaodTask = t.result;
        }
        return nil;
    }];
}
EN

回答 2

Stack Overflow用户

发布于 2019-04-26 22:38:29

我不是这方面的专家,但我在你的代码桶区域中注意到了一些东西:

initWithRegionType:AWSRegionUSEast1 identityPoolId:@"us-west-1:...

一旦我在代码中遇到类似的不匹配,bucket区域和Cognito身份池区域就不匹配,这就导致了问题。这可能是也可能不是你的代码中的情况,但只是根据我的经验添加一些信息。

代码语言:javascript
复制
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1 identityPoolId:@"us-west-1:7a24b199-e4b2-4657-9627-sdfs4ssdff"];
   AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:credentialsProvider];
票数 0
EN

Stack Overflow用户

发布于 2019-12-30 03:40:40

如果您认为SDK存在错误,可以尝试使用最新版本的SDK,如果您仍然看到问题,请在https://github.com/aws-amplify/aws-sdk-ios中打开一个问题,并执行一些再现步骤。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53994582

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档