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

  • SEARCH
  • Home
  • 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 3392776
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:58:08+00:00 2026-05-18T03:58:08+00:00

I am trying to use Valum’s Ajax Upload to do file uploads on a

  • 0

I am trying to use Valum’s Ajax Upload to do file uploads on a Django-
based site I am making. Currently I am avoiding a form simply because
AU sends the upload as the entirety of the POST data in an ajax
request. Right now I have a very naive approach to doing this:

upload = SimpleUploadedFile( filename, request.raw_post_data )
...then I loop through the chunks to write to disk...

This works great… on small files. I’ve tested with PDFs, various
other files, and up to the ~20MB Google Chrome deb package and they
all do great. However, if I move up to something like a CD or DVD iso
it bombs horribly. Often Django sends back an Out of Memory
response. On the surface this makes sense since SimpleUploadedFile is
an in-memory version of the upload classes. I cannot see how to use
TemporaryUploadedFile because it does not take actual content in its
constructor. As a side note: I would think after using up the
available RAM it would go to virtual memory, but whatever.

So, my question is, how do I get this to work? Is there a better way
to read in the file? I tried directly reading the raw_post_data via
Python’s IO (system uses 2.6.5) but FileIO’s ascii encoder/decoder
will obviously complain about non-ascii characters when working with
binary files. I have not been able to find info on changing the
encoder/decoder.

I wouldn’t mind passing the data into a form and having Django do the
work of picking the right upload class and so on, but I cannot figure
out how to pass it because something like

upload_form = UploadForm( request.POST, request.FILES )

will not work because the POST contains the file and not the normal
Django info and FILES does not exist.

As I said, I’m not worried about the method of the solution, just that
I get something that works! Thanks!

  • 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-05-18T03:58:09+00:00Added an answer on May 18, 2026 at 3:58 am

    Well I found two solutions if anyone is interested.

    The first is a pure-Python way of doing it that is moderately successful.

    with BufferedReader( BytesIO( request.raw_post_data ) ) as stream:
      with BufferedWriter( FileIO( "/tmp/foo.bar", "wb" ) ) as destination:
        foo = stream.read( 1024 )
        while foo:
          destination.write( foo )
          foo = stream.read( 1024 )
    

    It worked on testing for small files (up to 20MB) but failed when I tried it with ISOs (~600MB) or larger files. I didn’t try anything between the 20MB and 600MB so not sure where the break point is. I’ve copied the bottom of the trace below, I’m not sure what the root problem is in this situation. There seemed to be a struggle with memory, but I had enough RAM+swap to hold the file three times over so not sure why there was an issue. Not sure if using other forms of Python read/write or not using buffers would help here.

    [error] [client 127.0.0.1]   File "/usr/local/lib/python2.6 /dist-packages/django/core/handlers/wsgi.py", line 69, in safe_copyfileobj, referer: http://localhost/project/
    [error] [client 127.0.0.1]     buf = fsrc.read(min(length, size)), referer: http://localhost/project/
    [error] [client 127.0.0.1] TemplateSyntaxError: Caught IOError while rendering: request data read error, referer: http://localhost/project/
    

    The solution that has worked with everything I’ve thrown at it, up to 2GB files at least, required Django 1.3. They have added file-like support for reading directly from HttpRequest so I took advantage of that.

    with BufferedWriter( FileIO( "/tmp/foo.bar", "wb" ) ) as destination:
      foo = request.read( 1024 )
      while foo:
        destination.write( foo )
        foo = request.read( 1024 ) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read a value from a file and use it in a
I am trying to use the actual numerical value for the month on a
I' trying to use a Linq query to find and set the selected value
Trying to use an excpetion class which could provide location reference for XML parsing,
Trying to use a guid as a resource id in a rest url but
While trying to use LINQ to SQL I encountered several problems. I have table
I trying to use ImageInfo and Jython to get information from a image on
I'm trying to use svnmerge.py to merge some files. Under the hood it uses
I've been trying to use SQLite with the PDO wrapper in PHP with mixed
I'm trying to use SQLBindParameter to prepare my driver for input via SQLPutData .

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.