如何将文件/目录上载到bucket中的文件夹中?

时间:2020-12-27 01:46:37

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.

我可以用AWS。net SDK将文件或目录上载到一个桶中,但它们总是以根文件夹结束。

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

是否有办法将文件上载到现有目录?

  • edit. More info:
  • 编辑。更多信息:

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.

因此,我使用TransferUtilityUploadDirectoryRequest将一个目录从本地磁盘上传到S3。我希望这些文件被上载到bucket中的一个文件夹中,与我选择的文件夹同名。

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.

为例。如果我选择了目录c:/要上传的东西,我想要c的内容:/东西进入桶名/东西,而不是直接放进桶里。

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

我希望我正在努力做的事情是清楚的,如果没有,我将尝试提供更多的信息

2 个解决方案

#1


4  

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

net的AWS SDK的最新版本允许您在UploadDirectoryRequest(更多信息)上设置KeyPrefix属性。

#2


4  

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

#1


4  

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

net的AWS SDK的最新版本允许您在UploadDirectoryRequest(更多信息)上设置KeyPrefix属性。

#2


4  

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