【发布时间】:2017-02-15 03:41:57
【问题描述】:
我最近开始使用google-cloud client,并做了这个小例子(为了清楚起见,我省略/更改了一些内容):
<form id="testform" method="post" enctype="multipart/form-data">
<p>
<div>
<label for="fotos">Some file</label>
</div>
<div>
<input type="file" name="testfile">
</div>
</p>
<input type="submit" value="Submit">
</form>
from google.cloud import storage
class MyHandler(BaseHandler):
def get(self):
self.render("test.html")
def post(self):
file = self.request.POST["testfile"]
filename = file.filename # + TimeStamp
bucket = storage.Client().get_bucket(self.get_bucket_name())
blob = bucket.blob(filename)
blob.upload_from_string(data=file.file.read(),
content_type=file.type)
self.write(blob.public_url)
此代码适用于 32MB 以下的任何内容,但它无法处理较大的文件,因为它们通过应用程序而不是直接到 GCS。我已经看到solutions 使用 Blobstore API,但这些都是旧的,而且 Blobstore 甚至不再用于存储数据(尽管 Blobstore API 仍然可以使用)。
所以我想知道,有没有办法使用 google-cloud 客户端解决这个问题?我还没有看到在docs 中创建上传网址的方法。
【问题讨论】:
标签: python google-app-engine google-cloud-storage google-cloud-python