【问题标题】:I want to upload video files to S3 buckets from iPhone using iOS SDK?我想使用 iOS SDK 将视频文件从 iPhone 上传到 S3 存储桶?
【发布时间】:2017-02-03 09:49:14
【问题描述】:

我想使用 iOS SDK 将视频文件从 iPhone 上传到 S3 存储桶。 我需要帮助。我将图像上传到 Amazon S3,它工作正常,但是当我重写此代码以上传视频时,它出了点问题。

【问题讨论】:

    标签: ios video amazon-s3 upload sdk


    【解决方案1】:

    也许您应该在此处粘贴一些代码。此外,AWS SDK 有两个版本,您使用的是最新版本还是已弃用的版本?

    【讨论】:

      【解决方案2】:

      请查看amazon documentation,它将帮助您从基础开始,包括,

      1. 设置 SDK(使用框架设置 SDK 将是 初学者,详细信息将在此link)中提供)

      2. 获取 Cognito 客户端初始化代码(用于 AWS 身份验证 你的应用)

      3. 创建和配置 S3 存储桶

      完成上述步骤后,您可以轻松地将文件上传到 S3。在您的项目中实现以下代码,

      #import <AWSS3/AWSS3.h>
      #import <AWSCore/AWSCore.h>
      #import <AWSCognito/AWSCognito.h>

      - (void)viewDidLoad
      {
          [super viewDidLoad];
      /* Below three lines are called Cognito client initialization code please change the regiontype and indentityPoolId with yours */  
      
          AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSWest2 identityPoolId:@"us-west-2:73ab7333-bqw1-4a8e-b220-9f085cff50yo"];
      
          AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSWest2 credentialsProvider:credentialsProvider];
      
          [AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
      
          UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];  
          mediaUI.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;  
          mediaUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];  
          mediaUI.allowsEditing = YES;  
          mediaUI.delegate = self;  
      
          [self presentViewController:mediaUI animated:YES completion:nil];  
      
      
      }
      
      - (void)imagePickerController:(UIImagePickerController *) Picker didFinishPickingMediaWithInfo:(NSDictionary *)info
      {
          NSString *type = [info objectForKey:UIImagePickerControllerMediaType];  
      
          if ([type isEqualToString:(NSString *)kUTTypeVideo] ||
              [type isEqualToString:(NSString *)kUTTypeMovie]) { // movie != video  
      
              NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
              [self amazonS3Upload:videoURL];
           }
      }
      
      - (void)amazonS3Upload:(NSURL *) uploadUrl
      {
          // amazon web service s3 api
          AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];
      
          AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
          uploadRequest.bucket = @"myTest-bucket"; // Your Bucket Name
          uploadRequest.key = @"myTestFile.mp4"; // Your File Name in Bucket
          uploadRequest.body = uploadUrl;
          uploadRequest.uploadProgress =  ^(int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend){
              dispatch_async(dispatch_get_main_queue(), ^{
                  //Update progress.
                  NSLog(@"UPLOAD PROGRESS: %lld : %lld : %lld", bytesSent,totalBytesSent,totalBytesExpectedToSend);
              });
          };
      
          [[transferManager upload:uploadRequest] continueWithExecutor:[AWSExecutor mainThreadExecutor]
                      withBlock:^id(AWSTask *task) {
                                                                 if (task.error) {
                                                                     if ([task.error.domain isEqualToString:AWSS3TransferManagerErrorDomain]) {
                                                                         switch (task.error.code) {
                                                                             case AWSS3TransferManagerErrorCancelled:
                                                                             case AWSS3TransferManagerErrorPaused:
                                                                                 break;
      
                                                                             default:
                                                                                 NSLog(@"Error: %@", task.error);
                                                                                 break;
                                                                         }
                                                                     } else {
                                                                         // Unknown error.
                                                                         NSLog(@"Error: %@", task.error);
                                                                     }
                                                                 }
      
                                                                 if (task.result) {
                                                                     AWSS3TransferManagerUploadOutput *uploadOutput = task.result;
                                                                     NSLog(@"upload response: %@", uploadOutput);
                                                                     // The file uploaded successfully.
                                                                 }
                                                                 return nil;
                                                             }];
      
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-03-17
        • 2019-03-03
        • 1970-01-01
        • 2012-05-28
        • 2017-09-24
        • 1970-01-01
        • 2018-02-07
        相关资源
        最近更新 更多