2016-09-26 4 views

答えて

0

ここにコードを貼り付けてください。また、AWS SDKには2つのバージョンがありますが、最新のバージョンを使用していますか、または廃止予定のバージョンを使用していますか?

0

フレームワークを使用したSDK(セットアップSDKは、詳細はこの中で利用できるようになり、 スターターのための簡単な方法となります

  1. セットアップ、それはあなたが含む基本から開始するのに役立ちますamazon documentationに見てみてください。 のアプリのAWS認証の場合Cognitoクライアントの初期化コード()

  2. を取得link

  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; 
                 }]; 

} 
関連する問題