首页 > 解决方案 > aws s3 - 将目录及其子目录上传为 s3 存储桶

问题描述

我尝试通过代码将目录及其子目录传输到 s3 存储桶。在我的情况下,子目录是存储桶中的一个分区。如图所示: 在此处输入图像描述

标签: amazon-web-servicesamazon-s3aws-sdkamazon-athena

解决方案


您是否尝试将目录结构上传到 s3?

然后你可以用 CLI 试试这个:

aws s3 sync . s3://mybucket

https://docs.aws.amazon.com/cli/latest/reference/s3/sync.html

您也可以通过编程方式实现此目的:

TransferManager tm = new TransferManager(new ProfileCredentialsProvider());
MultipleFileUpload upload = tm.uploadDirectory(bucket, folder, new File(filePath), true);

try
{
    // Or you can block and wait for the upload to finish
    upload.waitForCompletion();
    LOGGER.debug("Upload complete.", bucket, folder);
}
catch (AmazonClientException amazonClientException)
{
    LOGGER.error("Unable to upload file, upload was aborted.", amazonClientException);
    throw amazonClientException;
}

https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/examples-s3-transfermanager.html


推荐阅读