Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a folder via s3cmd (Amazon S3)

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.

like image 679
John Avatar asked Jul 01 '11 21:07

John


People also ask

Can you create folders in S3?

Folders can be created, deleted, and made public, but they cannot be renamed. Objects can be copied from one folder to another. When you use the Amazon S3 console to create a folder, Amazon S3 creates a 0-byte object with a key that's set to the folder name that you provided.

Can we create folder in S3 bucket using CloudFormation?

You can use the CloudFormation template in the following resolution to use custom resources with an S3 bucket. Consider the following: The template allows you to create folders in S3 buckets. Amazon S3 has a flat structure, but supports the folder concept as a means of grouping objects.

Does AWS S3 cp create folder?

The Amazon S3 implements folder object creation by creating a zero-byte object. If you see a file in the console you will see the key of the file also has the folder reference in the key – test-folder/hdfs-0.0.

Do I need to create folder in S3 bucket?

Buckets are the top level containers in Amazon S3 for data storage. In order to start working with Amazon S3 you need to create at least one bucket. Once you have a buket, you may organize files by creating different folders inside the bucket to reflect the logical structure of your files.


2 Answers

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.

like image 89
Sabeen Malik Avatar answered Sep 26 '22 02:09

Sabeen Malik


This is how to create a folder:

s3cmd put foobar s3://bucket_name/new_directory/ 

To verify:

s3cmd la 
like image 27
Anand Kumar Avatar answered Sep 26 '22 02:09

Anand Kumar