我正在使用BlobstoreService将文件上传到AppEngine中的blobstore。 如何限制文件的内容类型或文件类型? 例如,我只想允许上传图像/ jpeg文件。
I'm using BlobstoreService for uploading a file to blobstore in AppEngine. How to restrict the content-type or file type of the file? For example, I only want to allow upload for image/jpeg files.
最满意答案
没有办法禁止用户上传一个禁止的文件类型a-priori,因为在他们进行POST之前你无法告诉他们要上传什么,并且没有干净的方法来中途终止POST请求。 您可以在上传文件后检测文件类型,但如果禁止,则从blobstore中删除该文件。
There's no way to prohibit the user from uploading a prohibited filetype a-priori, because you can't tell what they're going to upload until they make the POST, and there's no clean way to terminate a POST request partway through. You can detect the filetype after they've uploaded the file, and delete the file from the blobstore if it's prohibited, however.
更多推荐
发布评论