Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8787375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:52:33+00:00 2026-06-13T21:52:33+00:00

Suddenly when I upload a file to S3 it is uploading as 0 bytes.

  • 0

Suddenly when I upload a file to S3 it is uploading as 0 bytes.

I’m not sure why this is suddenly happening since it was working fine earlier. Here’s my code:

def store_in_s3_avatar(pathtofile, avatarimage, filename, user):
    conn = S3Connection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)
    b = conn.create_bucket('mybucket')
    mime = mimetypes.guess_type(filename)[0]
    k = Key(b)
    k.key = "/media/avatars/%s/%s" % (user,filename)
    k.set_metadata("Content-Type", mime)
    k.set_contents_from_string(avatarimage)
    k.set_acl("public-read")
    return pathtofile

Here’s the views.py snippet that calls this function:

 if request.method == "POST":
        updated = False
        if 'avatar' in request.FILES:
            path = avatar_file_path(user=request.user, 
                filename=request.FILES['avatar'].name)
            avatar = Avatar(
                user = request.user,
                primary = True,
                avatar = path,
            )
            new_file = avatar.avatar.storage.save(path, request.FILES['avatar'])
            avatarcontent = request.FILES['avatar']
            filename = request.FILES['avatar'].name
            avatarimage = avatarcontent.read()
            user=request.user
            avatar.avatar = store_in_s3_avatar(path, avatarimage, filename, user)
            avatar.save()
            ...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:52:34+00:00Added an answer on June 13, 2026 at 9:52 pm

    Based on the behavior you’re describing, I bet the file pointer is at the end because you just explicitly called the storage.save() function. By reading a file twice, you’ll get nothing.

    f = StringIO.StringIO('foobar')
    f.read() # out 'foobar'
    f.read() # out ''
    f.seek(0) 
    f.read() # out 'foobar'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suddenly this keeps happening during a JUnit test. Everything was working, I wrote some
Suddenly, local file access using jQuery's .getJSON is not working for me on Firefox
I have a script on my server for uploading file. It is working fine
My application was working fine but I don't know how suddenly allow_url_fopen set OFF
Suddenly today Visual Web Developer does not allow me to debug Silverlight applications. This
I am using move_uploaded_file to upload files in cakephp, this was working for a
Suddenly the scripts I was working on, are all stating this error when I
Suddenly I am not able to run my application on an emulator or device
Suddenly I started getting the following error: Fatal error: Class 'Mongo' not found in
I suddenly have an error in my Android eclipse project. This is after a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.