4

How can we add a file to an inner folder in a bucket? If there is a bucket named user --> i want to add it to the folder images/selected/ . Please help.

xydev
  • 3,409
  • 5
  • 34
  • 54

1 Answers1

6

This is what I do to upload a local file (localfilename.txt) to S3 and place files in 'folders' (image/selected/s3filename.txt).

AmazonCredentials * credentials = [[AmazonCredentials alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY];
putObjectRequest = [[[S3PutObjectRequest alloc] initWithKey:@"images/selected/s3filename.txt" inBucket:@"user"] autorelease];
[putObjectRequest setFilename:@"localfilename.txt"];
[putObjectRequest setCredentials:credentials];
[[AmazonClientManager s3] putObject:putObjectRequest];

Hope this helps. Cheers, Trond

Community
  • 1
  • 1
Trond Kristiansen
  • 2,379
  • 23
  • 48
  • i will try that [putObjectRequest setFilename:@"localfilename.txt"]; can you explain the line? @Trond Kristiansen – xydev Nov 29 '11 at 15:39
  • 1
    @xydev The command [putObjectRequest setFilename:@"localfilename.txt"]; just sets the name or path of the local file you want to upload (e.g. /users/test/localfilename.txt). The remote filename and path is set through the command [[[S3PutObjectRequest alloc] initWithKey:@"images/selected/s3filename.txt" inBucket:@"user"] – Trond Kristiansen Nov 29 '11 at 17:02