从iOS应用程序上传到AWS S3无法正常工作

时间:2014-07-30 14:16:30

标签: ios amazon-web-services amazon-s3

我使用的是AWS SDK 1.7.1版本。当我尝试上传捕获的图像时,应用程序不断崩溃。 (代码中指出的崩溃点)

我已经将AWS教程网页上提供的代码添加到T.但是发现了一些错误,其中一个我需要指定端点(在教程代码中没有明确说明) )。此外,教程代码包括[autorelease],表明它已过时。教程链接:https://aws.amazon.com/articles/3002109349624271

这里的任何人都知道更新的方式吗?

以下代码:

NSString *filename = [userid stringByAppendingString:randomString];

UIImage *image = self.image;

NSData *dataImage = [NSData dataWithData:UIImageJPEGRepresentation(image, .8)];

    // uplaod image to aws s3
AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithAccessKey:@"accesskey"
                                                 withSecretKey:@"secretaccesskey"];

//it puts the image in zee bucket
S3PutObjectRequest *por = [[S3PutObjectRequest alloc] initWithKey:[NSString stringWithFormat:@"%@.jpg", filename] inBucket:@"bucketname"];

por.contentType = @"image/jpeg";
por.data = dataImage;
por.endpoint = @"http://s3.amazonaws.com";

[s3 putObject:por];

// Get Response of the Request

S3ResponseHeaderOverrides *override = [[S3ResponseHeaderOverrides alloc] init];

override.contentType = @"image/jpeg";



S3GetPreSignedURLRequest *gpsurl = [[S3GetPreSignedURLRequest alloc] init];

gpsurl.key     = filename;

gpsurl.bucket  = @"zapstack_images";

gpsurl.responseHeaderOverrides = override;



NSURL *url = [s3 getPreSignedURL:gpsurl]; //CRASH OCCURRING HERE

0 个答案:

没有答案