问题
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
来源:https://stackoverflow.com/questions/9035893/calculate-size-multipart-form-data-encoded-file