2013-12-05 4 views
-2

Я загружаю видео в amazon bucket, он отлично работает, он обновляет файл, также показывает размер файла, но он не показывает расширение файла, и когда я загружаю файл, он просто показывает текстовый файл.iOS amazon загрузка видео с использованием S3

Он должен показать видеофайл, так как он показывает, что правильный размер не отображает файл.

вот код, который я использую.

-(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 [email protected]"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 [email protected]"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]; 
     }); 
    } 

}); 
    } 

Прагма знак - методы UIImagePickerControllerDelegate

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

ответ

3

Если вы установили вашей компании ntent для видео/quicktime вместо ролика/mov в обоих местах, которые вы его устанавливаете, и обновите переменную PICTURE_NAME, чтобы иметь расширение .mov, которое должно решить вашу проблему.

Смежные вопросы