2

求救,我需要帮助。我将图像上传到 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);
}
}

请指出我的错误。

非常感谢!!!

4

1 回答 1

7

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

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

于 2013-05-23T16:25:32.307 回答