topher-j
topher-j

Reputation: 2281

How do I upload a file/directory to a folder within a bucket?

I'm able to upload files or directories to a bucket with the AWS .NET SDK, but they always end up in the root folder.

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

So I'm using a TransferUtilityUploadDirectoryRequest to upload a directory from my local disk to S3. I would like the files to be uploaded to a folder in the bucket with the same name as the folder I've selected.

For example. if I choose the directory c:/stuff to be upload, I want the contents of c:/stuff to go in BucketName/stuff, not directly into the bucket.

I hope it's clear what I'm trying to do, if not I'll try to provide more info

Upvotes: 6

Views: 11353

Answers (2)

Jeff Barr
Jeff Barr

Reputation: 146

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

Upvotes: 6

Chuck Savage
Chuck Savage

Reputation: 11945

It seems after googling around, you specify a 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();

Upvotes: 7

Related Questions