ios amazon s3上传视频文件

时间:2013-05-23 15:09:29

标签: iphone ios video upload amazon

SOS,我需要帮助。我将图像上传到了亚马逊S3上,并且工作正常,但是当我重写上传视频的代码时,我认为这是错误的。正在上传MOV文件,但当我尝试在网址上从浏览器播放时,它告诉我:图片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);
}
}

请告诉我我的错误。

非常感谢!!!

1 个答案:

答案 0 :(得分:7)

排序。问题出在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,问题排序。