1

So, i'm trying to create an google app engine (python) app that allows people to share files. I have file uploads working well, but my concern is about checking the file extension and making sure, primarily, that the files are read only, and secondly, that they are of the filetype that is specified. These will not be image files, as a know they are a lot of image resources already. Specifically, .stl mesh files, but i'd like to be able to do this more generally.

I know there are modules that can do this, python-magic seems to be able to do this for example, but i can't seem to find any that i'm able to import without LoadModuleRestricted. I'm considering writing my own parser, but that would be a lot of work for such a common (i'm assuming) issue.

Anyway, i'm totally stumped so this is my first stackoverflow question, so hope i'm doing well etiquette wise. Let me know, and thanks!

4

1 回答 1

1

听起来您想读取上传文件的前几个字节以验证其签名是否与声称的 mime 类型匹配。假设您正在上传到 blobstore(即,通过从 获取的 url blobstore.get_upload_url(),那么一旦您被重定向到您提供的路径的上传处理程序get_upload_url,您可以使用BlobReader打开 blob ,然后读取并验证签名。

Blobstore 示例应用程序对框架进行了布局。UploadHandler一旦拥有blob_infoblob_info.key()用于打开 blob),您将在代码中粘贴。

于 2013-02-22T03:46:51.147 回答