Problem: S3 Objects Upload but Appear as Zero Bytes

 

Problem: S3 Objects Upload but Appear as Zero Bytes

$ aws s3 cp myfile.txt s3://my-data-bucket/
upload: ./myfile.txt to s3://my-data-bucket/myfile.txt

$ aws s3 ls s3://my-data-bucket/
2025-02-09 10:05:32         0  myfile.txt

$ aws s3api head-object --bucket my-data-bucket --key myfile.txt
{
    "AcceptRanges": "bytes",
    "LastModified": "2025-02-09T10:05:32.000Z",
    "ContentLength": 0,
    "ETag": "\"d41d8cd98f00b204e9800998ecf8427e\"",
    "ContentType": "text/plain",
    "Metadata": {}
}

Issue:

The file was uploaded, but it has zero bytes. Common causes include:

  • Empty source file – The local file being uploaded is empty.
  • Incorrect use of input redirection (> instead of >>) – Overwriting the file before upload.
  • Multipart upload issues – A failed multipart upload can leave a placeholder with no data.

Fix: Ensure the Source File Has Data & Retry Upload

# Step 1: Verify the local file size before uploading
$ ls -l myfile.txt
-rw-r--r-- 1 user user 0 Feb 9 10:00 myfile.txt   # File is empty!

# Step 2: Check the last few lines of the file to confirm content
$ tail -n 5 myfile.txt
# No output means the file is empty

# Step 3: If the file is empty, regenerate or fix the content
$ echo "This is a test file." > myfile.txt

# Step 4: Verify the file now has content
$ cat myfile.txt
This is a test file.

# Step 5: Re-upload the file to S3
$ aws s3 cp myfile.txt s3://my-data-bucket/
upload: ./myfile.txt to s3://my-data-bucket/myfile.txt

# Step 6: Verify the object size in S3
$ aws s3 ls s3://my-data-bucket/
2025-02-09 10:10:45        21  myfile.txt

$ aws s3api head-object --bucket my-data-bucket --key myfile.txt
{
    "AcceptRanges": "bytes",
    "LastModified": "2025-02-09T10:10:45.000Z",
    "ContentLength": 21,
    "ETag": "\"098f6bcd4621d373cade4e832627b4f6\"",
    "ContentType": "text/plain",
    "Metadata": {}
}

Need AWS Expertise?

If you're looking for guidance on AWS challenges or want to collaborate, feel free to reach out! We'd love to help you tackle your AWS projects. 🚀

Email us at: info@pacificw.com


Image: Gemini

Comments

Popular posts from this blog

The New ChatGPT Reason Feature: What It Is and Why You Should Use It

Raspberry Pi Connect vs. RealVNC: A Comprehensive Comparison

The Reasoning Chain in DeepSeek R1: A Glimpse into AI’s Thought Process