3

I'm writing an application that should receive a file and store it.

One way of storing would be to upload it to another server (e.g. filehoster). Server-side I'm using Python and the Pyramid-framework. I already get rid of the problem getting the file while the client is uploading, and wrapped the app returned by make_wsgi_app in another class. This class handles the upload request and I'm able to only read the file.

My current problem is getting the file size while the client is uploading. The client sends the request multipart/form-data encoded so the content-length header includes the size of the boundarys and content-type declarations.

I think it's a bad idea to just subtract a fix size because anything in the form can change and the whole file-part would be broken.

I read another question about this topic but I don't want to use another lib. I think there has to be a half-way easy way to do this in pure python.
Thanks

Reddy
  • 8,737
  • 11
  • 55
  • 73
Felix Scheinost
  • 423
  • 1
  • 4
  • 14
  • Can you link to the other question you mentioned? – AdamKG Jan 27 '12 at 16:40
  • Is this helping: [pyramid.request](http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/api/request.html#pyramid.request.Request.content_length) ? – Cornel Ghiban Jan 27 '12 at 17:00
  • This is the question - but for java:http://stackoverflow.com/questions/5920689/how-to-know-the-file-size-when-uploading-via-multipart-form-data – Felix Scheinost Jan 29 '12 at 08:04
  • No, my handler get's called before pyramid creates the request object, and my problem isn't to get the content-length of the whole body but of the file part itself. – Felix Scheinost Jan 29 '12 at 08:07

0 Answers0