0

私は運が悪いので、かなり長い間この問題に取り組んできました。http://aws.amazon.com/articles/3002109349624271に従って、Amazon S3 iOS アップロード SDK を使用しています。

症状: バケットを作成できますが、画像をアップロードできません。 S3PutObjectResponse *putObjectResponse = [self.s3 putObject:por];ゼロを返します。

ここに私のコードがあります :

self.s3 = [[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY];
self.s3.endpoint = [AmazonEndpoints s3Endpoint:US_WEST_2];

エンドポイントの有無にかかわらず試しました。https://forums.aws.amazon.com/thread.jspa?messageID=427879蝧に従って追加

同じView Controllerで後で呼び出されるアップロード機能では:

...
NSData *data = UIImageJPEGRepresentation(newImage, 0.9);
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:PICTURE_BUCKET];
        por.contentType = @"image/jpeg";
        por.data = data;
        por.delegate = self;

        // Put the image data into the specified s3 bucket and object.
        S3PutObjectResponse *putObjectResponse = [self.s3 putObject:por];

        dispatch_queue_t queue = dispatch_get_main_queue();
        dispatch_async(queue, ^{
            if(putObjectResponse.error != nil)
            {
                NSLog(@"Error: %@", putObjectResponse.error);
                [self showAlertMessage:[putObjectResponse.error.userInfo objectForKey:@"message"] withTitle:@"Upload Error"];
            }
        });


        NSLog(@"image PUT to amazon");
        // Set the content type so that the browser will treat the URL as an image.
        S3ResponseHeaderOverrides *override = [[S3ResponseHeaderOverrides alloc] init];
        override.contentType = @"image/jpeg";

        // Request a pre-signed URL to picture that has been uploaded.
        S3GetPreSignedURLRequest *gpsur = [[S3GetPreSignedURLRequest alloc] init];
        gpsur.key                     = PICTURE_NAME;
        gpsur.bucket                  = PICTURE_BUCKET;
        gpsur.expires                 = [NSDate dateWithTimeIntervalSinceNow:(NSTimeInterval) 7200]; // Added an hour's worth of seconds to the current time.
        gpsur.responseHeaderOverrides = override;

        // Get the URL
        NSError *error;
        NSURL *url = [self.s3 getPreSignedURL:gpsur error:&error];

        NSString *imageURL = url.absoluteString;
        NSLog(@"%@",imageURL);
    });

エラーがスローされることはなく、URL にアクセスすると、単に「指定されたキーが存在しません」と表示されます。

何かアイデアがありましたら、お知らせください。これは私を夢中にさせています!

4

0 に答える 0