Search code examples
javaandroidamazon-web-servicesamazon-s3aws-amplify-sdk-android

How to create an empty folder in aws S3 bucket with using Android Sdk?


I understand the concept of folders and objects in Aws S3 bucket, that there is no folder and all are objects. But I need to create an empty folder where user can enter and upload their files. I have tried several things like adding a test .txt file with a path which extends the empty folder's name after "/" and it do create the folder but it keeps the test.txt file which if I delete also deletes the folder created.

So any idea about how to create an zero size empty folder object as is created in the web console of S3 storage? Any help would be great


Solution

  • Use your SDK of choice to create an S3 object named, for example, folder1/folder2/cats/ with a size of 0 bytes. This assumes that your preferred folder separator is /, which is obviously the most commonly used separator, but you could use anything you like.

    Here is a generic Java upload an object example. Modify this so that the object key is folder1/folder2/cats/ and no content is uploaded.