ios amazon s3 上传视频文件

Posted

技术标签:

【中文标题】ios amazon s3 上传视频文件【英文标题】:ios amazon s3 uploading video file 【发布时间】:2013-05-19 00:40:35 【问题描述】:

求救,我需要帮助。我将图像上传到 Amazon S3,它工作正常,但是当我重写此代码以上传视频时,它有些错误。正在上传 MOV 文件,但是当我尝试从 url 在浏览器上播放它时,它告诉我:图像 https... 无法显示,因为它包含错误。

这是我的代码:

- (BOOL) startMediaBrowserFromViewController: (UIViewController*) controller
                           usingDelegate: (id <UIImagePickerControllerDelegate,
                                           UINavigationControllerDelegate>) delegate
// Get image picker
UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];
mediaUI.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
mediaUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
mediaUI.allowsEditing = YES;
mediaUI.delegate = delegate;

// Display movie files
[controller presentModalViewController:mediaUI animated:YES ];

- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info 

[self dismissModalViewControllerAnimated:YES];
UIImage *image = (UIImage*) [info objectForKey:UIImagePickerControllerOriginalImage];    

fileName = "anyName.MOV";
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);

@try 
    S3PutObjectRequest *por = [[S3PutObjectRequest alloc] initWithKey:fileName inBucket:MY_BUCKET];
    por.contentType = @"movie/mov";
    por.cannedACL   = [S3CannedACL publicRead];
    por.data        = imageData;
    [s3 putObject:por];


@catch (AmazonClientException *exception) 
    NSLog(@"exception %@", exception);


请指出我的错误。

非常感谢!!!

【问题讨论】:

您从 AWSSDK 导入哪个库来访问 S3PutObjectRequest? 对于 MY_BUCKET 你用了什么?因为我得到 AmazonServiceException RequestId:C25210BBC515D041, ErrorCode:NoSuchBucket, Message: The specified bucket does not exist 【参考方案1】:

已排序。问题出在 Image 对象上。所以我只是通过以下方式获得了视频网址:

NSURL *image = [info objectForKey:UIImagePickerControllerMediaURL];

相反

UIImage *image = (UIImage*) [info objectForKey:UIImagePickerControllerOriginalImage];

然后从 url 传递 NSData,所以我确实替换了行

NSData *imageData = UIImageJPEGRepresentation(image, 1.0);

到:

NSData *imageData = [NSData dataWithContentsOfURL:image];

还有 tataaaaaaaa,问题已解决。

【讨论】:

以上是关于ios amazon s3 上传视频文件的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Android 应用程序中播放来自 Amazon S3 的视频?

从 iOS 应用上传到 Amazon S3

使用retrofit2视频/图像损坏的AWS S3文件上传

Amazon S3 - 匿名 TVM 与身份 TVM

Amazon S3 存储桶大文件上传

上传amazon s3后获取文件url