开发者

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?

  • edit. More info:
开发者_JAVA百科

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


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();


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜