Calculate size multipart/form-data encoded file

喜夏-厌秋 提交于 2020-01-24 09:04:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!