Appearance
Upload Objects to a Bucket (s3cmd)
This guide shows how to upload objects to a bucket using s3cmd, an S3‑compatible command‑line tool.
If you haven’t set up s3cmd yet, follow the separate guide first: Install & Configure s3cmd.
Prerequisites
- A bucket already created. If you need one, see Create a Storage Bucket.
- S3 credentials (Access Key ID and Secret Access Key).
- Your S3 endpoint URL and, if applicable, region (provided by your cloud).
Steps
Verify configuration
List buckets to confirm s3cmd is configured and can reach the endpoint:
bash
s3cmd lsIf you see your buckets listed, you’re ready. If not, re-run configuration per the install guide.
Upload a single file
Upload a local file to your bucket root:
bash
s3cmd put ./path/to/photo.jpg s3://my-bucket/Upload to a specific prefix (folder path):
bash
s3cmd put ./path/to/photo.jpg s3://my-bucket/images/Upload a directory (sync)
Use sync to upload a directory tree. The trailing slash patterns control how paths map into the bucket.
bash
# Upload contents of ./site/ into s3://my-bucket/site/
s3cmd sync ./site/ s3://my-bucket/site/
# Upload entire ./backups directory under the bucket root
s3cmd sync ./backups s3://my-bucket/Useful flags:
--delete-removed: remove remote files not present locally (use with care).--dry-run: preview changes without uploading.
Verify upload
List objects in a path:
bash
s3cmd ls s3://my-bucket/
s3cmd ls s3://my-bucket/images/Optional — Set object metadata or ACL
You can set cache headers or make specific objects public (if your policy allows):
bash
# Example: upload with Cache-Control metadata
s3cmd --add-header='Cache-Control:max-age=31536000' put app.js s3://my-bucket/assets/
# Example: upload and make object publicly readable
s3cmd --acl-public put logo.png s3://my-bucket/assets/Notes:
- Public access may require the bucket/container to permit public reads. See Public Access & Website.
- Metadata support can vary by backend; verify effective headers by fetching the object.
Troubleshooting
- Auth or signature errors: Confirm Access/Secret keys and that Signature V4/V2 settings match the service. Re-run
s3cmd --configure. - Endpoint/host errors: Ensure
host_baseandhost_bucketmatch your provider’s endpoint (path‑style vs. virtual‑host style). - Permission denied: Check your bucket policy/ACLs and that your user has write permissions.