Genhain
Genhain

Reputation: 1937

IOS AWS s3 bucket image uploading problems

Been trying to get this to work for a while know i have tried it with data and with streaming but with no luck, I assume i do not need to create the bucket as shown in most examples as the bucket i want to upload to already exists, also it tells me the bucket i am trying to access, however when i try to upload i get this

"Error uploading image to S3: The XML you provided was not well-formed or did not validate against our published schema"

here is the code

UIImage * img = [[[[CurrentGamesInfo sharedCurrentGamesInfo]GameInCreation] GetImageToSend]_imageToSend];
    NSData *savedImageData = UIImageJPEGRepresentation(img, 0.8);
    NSString *pictureName = [[[CurrentGamesInfo sharedCurrentGamesInfo]GameInCreation] GetGameID];

    @try 
    {
        AmazonS3Client *s3 = [[[AmazonS3Client alloc] initWithAccessKey:MY_ACCESS_KEY_ID withSecretKey:MY_SECRET_KEY] autorelease];

        //[s3 createBucket:[[[S3CreateBucketRequest alloc] initWithName:MY_PICTURE_BUCKET] autorelease]];
        NSArray *bucketArray = [s3 listBuckets];
        S3Bucket *bucket = [[s3 listBuckets] objectAtIndex:0];
        NSLog(@"%@",[bucket name]);


        S3PutObjectRequest *por = [[[S3PutObjectRequest alloc] initWithKey:pictureName inBucket:MY_PICTURE_BUCKET] autorelease];
        por.contentType = @"image/jpeg";

        //por.data = savedImageData;
        //por.cannedACL   = [S3CannedACL publicRead];

        S3UploadInputStream *stream = [S3UploadInputStream inputStreamWithData:savedImageData];
        //stream.delay = 0.2; 
        //stream.packetSize = 16;
        por.contentLength = [savedImageData length];
        por.stream = stream;

        [s3 putObject:por];      
    }
    @catch (AmazonClientException *exception) 
    {
        NSLog(@"Error uploading image to S3: %@", exception.message);
    }

sooooo...what am i doing wrong?

Upvotes: 0

Views: 1253

Answers (1)

Genhain
Genhain

Reputation: 1937

Nevermind...the variable "pictureName" was nil...I slink away in shame

Upvotes: 5

Related Questions