gpt4 book ai didi

ios - 在 iOS 上使用 AWS 将视频文件上传到现有存储桶时出现问题

转载 作者:行者123 更新时间:2023-11-29 10:48:01 26 4
gpt4 key购买 nike

我正在使用亚马逊提供的示例制作一个应用程序,将视频上传到服务器 (S3)。该示例生成一个存储桶并在其中存储图像。就我而言,我使用之前生成的存储桶来存储视频,但如果我删除存储桶生成代码,视频上传就会停止。生成的桶不用于存储视频。此外,如果存储桶生成抛出异常(例如因为存储桶已经存在),文件上传仍然有效。

我想在发送文件之前我还需要做另一项初始化工作。有什么想法吗?

这是我的代码:

- (void)viewDidLoad
{
[super viewDidLoad];
self.s3 = nil;
aws_bucketName = @"bucketname"; // this is not the real name
aws_key = @"**** HIDDEN ********";
aws_secretKey = @"**** HIDDEN ********";

if(self.s3 == nil)
{
// Initial the S3 Client.
self.s3 = [[AmazonS3Client alloc] initWithAccessKey:aws_key withSecretKey:aws_secretKey];
self.s3.endpoint = [AmazonEndpoints s3Endpoint:US_EAST_1]; // the bucket region is 'US Standard'

//*******************************//
// @try
// {
// // Create the picture bucket.
// NSLog(@"Start with bucket generation");
// S3CreateBucketRequest *createBucketRequest = [[S3CreateBucketRequest alloc] initWithName:aws_bucketName andRegion:[S3Region USStandard]];
//
// NSLog(@"Buquet requested, now response [bucket: %@]", aws_bucketName);
// S3CreateBucketResponse *createBucketResponse = [self.s3 createBucket:createBucketRequest];
//
// NSLog(@"Bucket generated");
// if(createBucketResponse.error != nil)
// {
// NSLog(@"Error: %@", createBucketResponse.error);
// }
// }
//
// @catch (NSException *exception)
// {
// NSLog(@"There was an exception when connecting to s3: %@",exception.description);
// }
//**********************************//
}
}

- (IBAction)uploadFileButtonTouchUp:(id)sender
{
NSLog(@"Upload started");
// Get file path
NSString* fileName = @"upTest.mp4";
NSString *fileDirectory = [[NSBundle mainBundle] resourcePath];
NSString *finalFilePath = [fileDirectory stringByAppendingFormat:@"/%@", fileName ];

NSLog(@"The file to be uploaded is: %@", finalFilePath);
// Call file upload
NSURL *videoURL = [NSURL fileURLWithPath:finalFilePath];
NSData *videoData = [NSData dataWithContentsOfURL:videoURL];
[self uploadWithData2:videoData videoName:@"iosUploadTest.mp4" bucketName:aws_bucketName];
}


//*************************************************//
//********* File upload **********//
//*************************************************//
- (void)uploadWithData2:(NSData *)data videoName:(NSString *)videoName bucketName:(NSString*)bucketName
{
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:videoName
inBucket:bucketName];
por.contentType = @"movie/mov";
por.data = data;

// 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);
}
else
{
NSLog(@"Video uploaded succesfuly");
}

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
});
});
}

bucket生成代码有注释

最佳答案

尝试将内容类型设置为 video/mp4 以减轻 MIME 类型可能出现的不可预见的问题。

我也会建议 reading this ,它包含一些不同的上传方法,并像您一样处理线程。

关于ios - 在 iOS 上使用 AWS 将视频文件上传到现有存储桶时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21709911/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com