我正在将视频上传到亚马逊水桶它工作得很好它uplaodes文件也显示文件大小但它没有显示任何文件扩展名,当我下载文件时它只显示文本文件。
它应该显示视频文件,因为它显示正确的大小不显示文件。
这是我正在使用的代码。
-(IBAction)uploadPhotoWithGrandCentralDispatch:(id)sender
{
[self showImagePicker:GrandCentralDispatch];
}
- (void)processGrandCentralDispatchUpload:(NSData *)imageData
{
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
// Upload image data. Remember to set the content type.
S3PutObjectRequest *por = [[[S3PutObjectRequest alloc] initWithKey:PICTURE_NAME
inBucket:[Constants pictureBucket]] autorelease];
// por.contentType = @"image/jpeg";
por.contentType =@"movie/mov";
por.data = imageData;
// Put the image data into the specified s3 bucket and object.
S3PutObjectResponse *putObjectResponse = [self.s3 putObject:por];
dispatch_async(dispatch_get_main_queue(), ^{
if(putObjectResponse.error != nil)
{
NSLog(@"Error: %@", putObjectResponse.error);
[self showAlertMessage:[putObjectResponse.error.userInfo objectForKey:@"message"] withTitle:@"Upload Error"];
}
else
{
// [self performSelectorOnMainThread:@selector(dataDoneLoading:) withObject:nil waitUntilDone:NO];
[self performSelectorOnMainThread:@selector(dataDoneLoading:) withObject:imageData waitUntilDone:NO];
[self showAlertMessage:@"The image was successfully uploaded." withTitle:@"Upload Completed"];
}
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
});
});
}
#pragma mark - AmazonServiceRequestDelegate
-(IBAction)uploadPhotoWithDelegate:(id)sender
{
[self showImagePicker:Delegate];
}
- (void)processDelegateUpload:(NSData *)imageData
{
// Upload image data. Remember to set the content type.
S3PutObjectRequest *por = [[[S3PutObjectRequest alloc] initWithKey:PICTURE_NAME
inBucket:[Constants pictureBucket]] autorelease];
//por.contentType = @"image/jpeg";
//Madi work///
por.contentType =@"movie/mov";
por.data = imageData;
por.delegate = self;
// Put the image data into the specified s3 bucket and object.
[self.s3 putObject:por];
}
-(void)request:(AmazonServiceRequest *)request didCompleteWithResponse: (AmazonServiceResponse *)response
{
[self showAlertMessage:@"The image was successfully uploaded." withTitle:@"Upload Completed"];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
-(void)request:(AmazonServiceRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"Error: %@", error);
[self showAlertMessage:error.description withTitle:@"Upload Error"];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
-(IBAction)uploadPhotoWithBackgroundThread:(id)sender
{
[self showImagePicker:BackgroundThread];
}
- (void)processBackgroundThreadUpload:(NSData *)imageData
{
[self performSelectorInBackground:@selector(processBackgroundThreadUploadInBackground:)
withObject:imageData];
}
- (void)processBackgroundThreadUploadInBackground:(NSData *)imageData
{
// Upload image data. Remember to set the content type.
S3PutObjectRequest *por = [[[S3PutObjectRequest alloc] initWithKey:PICTURE_NAME
inBucket:[Constants pictureBucket]] autorelease];
// por.contentType = @"image/jpeg";
por.contentType = @"movie/mov";
por.data = imageData;
// Put the image data into the specified s3 bucket and object.
S3PutObjectResponse *putObjectResponse = [self.s3 putObject:por];
[self performSelectorOnMainThread:@selector(showCheckErrorMessage:)
withObject:putObjectResponse.error
waitUntilDone:NO];
}
- (void)showCheckErrorMessage:(NSError *)error
{
if(error != nil)
{
NSLog(@"Error: %@", error);
[self showAlertMessage:[error.userInfo objectForKey:@"message"] withTitle:@"Upload Error"];
}
else
{
[self showAlertMessage:@"The image was successfully uploaded." withTitle:@"Upload Completed"];
}
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
-(IBAction)showInBrowser:(id)sender
{
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
// Set the content type so that the browser will treat the URL as an image.
S3ResponseHeaderOverrides *override = [[[S3ResponseHeaderOverrides alloc] init] autorelease];
//override.contentType = @"image/jpeg";
override.contentType = @"movie/mov";
// Request a pre-signed URL to picture that has been uplaoded.
S3GetPreSignedURLRequest *gpsur = [[[S3GetPreSignedURLRequest alloc] init] autorelease];
gpsur.key = PICTURE_NAME;
gpsur.bucket = [Constants pictureBucket];
gpsur.expires = [NSDate dateWithTimeIntervalSinceNow:(NSTimeInterval) 3600]; // Added an hour's worth of seconds to the current time.
gpsur.responseHeaderOverrides = override;
// Get the URL
NSError *error = nil;
NSURL *url = [self.s3 getPreSignedURL:gpsur error:&error];
if(url == nil)
{
if(error != nil)
{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Error: %@", error);
[self showAlertMessage:[error.userInfo objectForKey:@"message"] withTitle:@"Browser Error"];
});
}
}
else
{
dispatch_async(dispatch_get_main_queue(), ^{
// Display the URL in Safari
[[UIApplication sharedApplication] openURL:url];
});
}
});
}
-(void) dataDoneLoading:(id) obj {
[alert dismissWithClickedButtonIndex:0 animated:YES];
}
-(void)uploadAllData :(id) obj{
[self processGrandCentralDispatchUpload:imageData];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Get the selected image.
// UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// Convert the image to JPEG data.
NSURL *image = [info objectForKey:UIImagePickerControllerMediaURL];
// imageData = UIImageJPEGRepresentation(image, 1.0);
imageData = [NSData dataWithContentsOfURL:image];
if(_uploadType == GrandCentralDispatch)
{
alert= [[UIAlertView alloc] initWithTitle:@"Uploading Data\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(150, 100);
[indicator startAnimating];
[alert addSubview:indicator];
[NSThread detachNewThreadSelector:@selector(uploadAllData:) toTarget:self withObject:nil];
}
else if(_uploadType == Delegate)
{
[self processDelegateUpload:imageData];
}
else if(_uploadType == BackgroundThread)
{
[self processBackgroundThreadUpload:imageData];
}
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[picker dismissModalViewControllerAnimated:YES];
}
答案 0 :(得分:3)
如果您在两个地方都将内容类型设置为video / quicktime而不是movie / mov,则设置它并更新PICTURE_NAME变量以使用扩展名.mov来解决您的问题。