我正在尝试从我的应用引擎应用上传到云存储,但它会不断上传文件名而不是内容。
html非常简单:
<form id="uploadbanner" enctype="multipart/form-data" action="/upload">
<input id="fileupload" name="myfile" type="file" />
<input type="submit" value="submit" id="submit" />
</form>
python元素是这样的:
class Uploader(webapp2.RequestHandler):
def get(self):
objectname = '%s'%str(uuid.uuid4())
objectpath = '/gs/bucketname/%s' %objectname
upload = self.request.get('myfile')
writable = files.gs.create(filename=objectpath, mime_type='application/octet-stream', acl='public-read')
with files.open(writable, 'a') as f:
f.write(upload)
files.finalize(writable)
self.response.write('done')
我知道f.write(upload)
肯定是错的,但我不知道我应该用
答案 0 :(得分:1)
您可能应该让浏览器直接上传到GCS,然后只让您的处理程序调用。
要简要了解如何完成此操作,请查看以下文章:Upload images/video to google cloud storage using Google App Engine
即使在此示例中似乎调用了blobstore API,文件也会上传到云存储。
答案 1 :(得分:1)
它需要POST而不是GET,所以将method="POST"
添加到表单并使python函数发布而不是得到它,它为我排序。