Friday, August 12, 2011

Upload file to folder in S3 bucket using AWS SDK .NET

While managing to create a function that utilizes AWS SDK for .NET in order to upload files to S3 buckets, I still can't find the attribute to pass to the PutObjectRequest instance that will allow me to tell it the folder inside the bucket that I want to copy the object to. Right now the only option I've found is to be able to upload files to the root of the Amazon S3 bucket, which is not what I want.

If you know what should I change in this code in order to be able to upload files to a specific folder which was previously create on Amazon S3, instead of just the root - Please comment.

I also posted the question on StackOverflow too.


The answer was quite simple and thanks for Brian Dishaw from StackOverflow for answering my question. What you need to do is to add the folder to the request.WithKey function like this:

request.WithKey(toWhichFolder + "/" + uploadAsFileName) );

The toWhichFolder argument is defined in my UploadFileToS3 function, so I can call the upload function with different folder values. So by changing the WithKey to accept a folder name, the file will be uploaded to the specific folder inside the Amazon S3 bucket that I passed its name via request.WithBucketName(toWhichBucketName).

Simple answer and thanks Brian for your support.

No comments:

Post a Comment