How to upload a file / directory to a folder in a bucket?

I can upload files or directories to the bucket using the AWS.NET SDK, but they always get to the root folder.

Is there a way to upload a file to an existing directory?

  • edit. Additional Information:

Therefore, I use TransferUtilityUploadDirectoryRequest to load the directory from my local drive to S3. I would like the files to be uploaded to a folder in a bucket with the same name as the folder of your choice.

For instance. if I select the c: / stuff directory to load, I want the contents of c: / stuff to be included in BucketName / stuff, and not directly in the bucket.

I hope it is clear what I am trying to do, if not, I will try to provide additional information

+5
source share
2 answers

The newest version of the AWS SDK for .NET allows you to set the KeyPrefix property in UploadDirectoryRequest (more here ).

+4
source

It seems, after googling, you specify the key. It took me a while, but I believe the key is something like this example:

string key = string.Format("{0}/{1}", folder, filename); 
PutObjectRequest rq = new PutObjectRequest()
{
    AutoCloseStream = false,
    BucketName = s3BucketName,
    InputStream = stream,
    Key = key
};

S3ClientInstance.PutObject(rq).Dispose();
+4
source

All Articles