首页 > 解决方案 > 使用谷歌云存储“附件”

问题描述

我在应用程序引擎中有一个(ndb.model)“表”,我需要向其中添加“附件”,例如 .jpg、.doc、xls 等。我无法预先确定这些文件将是什么,这取决于用户。使用 blobkey / blobstore 相当容易,但为此我在使用 Google Cloud Storage 时遇到了麻烦。

我的 html 很简单:

<label for="form_attach">Please select Attachment</label>
<input type="file" name="form_attach" id="form_attach" />

我的 Python 代码也很简单:

tempblob = self.request.get('form_attach')
logging.error(repr(tempblob))  -- shows the contents of tempblob

那么......我如何知道传入 blob 的内容类型(mime 类型),以便我可以正确地将其保存在 Google Cloud Storage 中?我需要在存储 blob 时设置内容类型,以便它能够正确服务/显示。

gcs.stat(...).content_type 看起来像是我需要的,但它需要一个有效的、已存储的 GCS 文件来检索信息。同样,Python 的 mimetypes 需要一个文件名,但我似乎检索了文件的内容。

任何指针将不胜感激。

谢谢大卫

标签: pythongoogle-app-enginegoogle-cloud-storage

解决方案


Jeff O'Neill's link provided the answers I was looking for, thanks. Question will be closed.


推荐阅读