Amazon Web Services (AWS) S3 Java create a sub directory (object)

前端 未结 6 1207
孤城傲影
孤城傲影 2021-01-31 17:24

I am familiar with AWS Java SDK, I also tried to browse the corresponding Javadoc, but I could not realize how do I create a sub directory, i.e., a directory object within a buc

6条回答
  •  深忆病人
    2021-01-31 18:12

    Leaving this answer here just in case someone stumbles upon this. I have been using aws sdk version - 1.11.875 and the following successfully created a folder for me when trying to upload a file into S3 bucket. I did not have to explicitly create the folder as mentioned in the earlier answer.

    private void uploadFileToS3Bucket(final String bucketName, final File file) {
        final String fileName = "parent/child/" + file.getName();
        final PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, fileName, file);
        amazonS3.putObject(putObjectRequest);
    }
    

    This will create the parent and parent/child folders in the specified S3 bucket and upload the file into child folder.

提交回复
热议问题