python - 使用谷歌云存储“附件”
问题描述
我在应用程序引擎中有一个(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 需要一个文件名,但我似乎检索了文件的内容。
任何指针将不胜感激。
谢谢大卫
解决方案
Jeff O'Neill's link provided the answers I was looking for, thanks. Question will be closed.
推荐阅读
- jquery - jQuery - 仅在移动设备上运行功能
- python - Trouble using Python ctypes to run C dll function (array output with unknown size)
- javascript - Angular 应用程序中的外部 JavaScript 库
- python - 如何让 Selenium 在 Python 中重复一个命令?
- mysql - 同时按两列排序
- r - 在 R 中解析日期
- linux - 使用“=”作为分隔符拆分字符串的内容
- mysql - X 部门人受 Y 部门人控制
- python - 为什么这个记忆化的 Euler14 实现在 Raku 中比 Python 慢得多?
- angular - npm 未安装最新版本的 ngx-bootstrap 6.2.0