在Google App Engine(Java)中限制Blobstore上传的文件类型

在Google App Engine(Java)中限制Blobstore上传的文件类型

问题描述:

我正在使用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请求.您可以在文件上传后检测到文件类型,但是如果禁止,则可以从Blob存储区中删除该文件.

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.