GAE/python:如何从Cloud Storage(GCS)解析多部分数据文件? [英] GAE/python: How to parse multipart data file from Cloud Storage (GCS)?

查看:82
本文介绍了GAE/python:如何从Cloud Storage(GCS)解析多部分数据文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照gae/python代码将文件上传到GCS(来自Webform的输入文件):-

I am uploading file to GCS (input file from webform) by following gae/python code:-

fx = self.request.body_file
gcs_file = gcs.open(_GCS_BUCKET_NAME + "new_file_name", 'w')
gcs_file.write(fx.read())

我可以使用以下代码从GCS检索此上传的数据

I am able to retrieve this uploaded data from GCS with following code

gcs_file = gcs.open(_GCS_BUCKET_NAME + "new_file_name", 'r')
self.response.write(gcs_file.read())

由于上传的数据是多格式数据,如何从gcs_file.read()中提取原始文件名和原始文件(二进制数据)本身?

Since the uploaded data is multiform data, how do I extract original file name, and original file (binary data) itself from gcs_file.read() ?

推荐答案

您可以使用原始文件名将文件保存在GCS中

You can save the file in GCS with its original file name

您可以创建一个小的DataStore数据库,其中的实体具有原始文件名的数据以及在GCS中对文件的引用

You can create a small DataStore DB where with an entity having the data of your original file name and a reference to your file in GCS

为什么原始二进制文件应该与众不同?

Why should the original binary be different?

如果您已成功从GCS下载了该文件,则可以确认二进制文件实际上是相同的.

If you have managed to download it from GCS you can verify the binary is actually the same.

这篇关于GAE/python:如何从Cloud Storage(GCS)解析多部分数据文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆