【发布时间】:2018-10-22 01:27:32
【问题描述】:
我在应用引擎中有一个(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 需要一个文件名,但我似乎检索了文件的内容。
任何指针将不胜感激。
谢谢 大卫
【问题讨论】:
-
您可能会觉得这很有帮助:blog.whiteoctober.co.uk/2016/08/01/…
-
谢谢杰夫,非常感谢
标签: python google-app-engine google-cloud-storage