Creating a folder via s3cmd (Amazon S3)

John picture John · Jul 1, 2011 · Viewed 31.6k times · Source

I am using s3cmd to upload files to my S3 server. My problem is that when a directory on the server does not exist the upload fails. How can I tell s3cmd to create the folder if it does not exist? I am using PHP.

Answer

Sabeen Malik picture Sabeen Malik · Jul 2, 2011

I believe you should try something like s3cmd put file.jpg s3://bucket/folder/file.jpg.

S3 doesn't have the concept of directories, the whole folder/file.jpg is the file name. If using a GUI tool or something you delete the file.jpg from inside the folder, you will most probably see that the folder is gone too. The visual representation in terms of directories is for user convenience.