如何通过应用程序引擎将图像上传到云存储? [英] how to upload image to the cloud storage via app engine?
本文介绍了如何通过应用程序引擎将图像上传到云存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在谷歌应用程序引擎中使用python。
我想从浏览器中获取图片并将其上传到云存储。
表单:
< form action =http://myappId.appspot.com/test/uploadImagemethod =post>
< input type =filename =filevalue ='file'>< br>
< input type =submitvalue =Submit>
< / form>
我的服务器端:
image = self.request.get(file)
gcs_file = gcs.open (GCS_BUCKET_NAME +'testImage.png','w')
gcs_file.write(image.encod('utf-8'))
gcs_file.close()
self。 response.write(success!)
保存在云存储中的文件,但问题是我无法下载它,我得到这个错误:
文件无法打开,它可能被损坏或用户a预览无法识别的文件格式!
我该怎么办?
我不希望使用blobstore,因为 create_upload_url
会在十分钟内激活。
解决方案
这可能是因为您的表单没有正确的 enctype =multipart / form-data
吗?
I am using python with google app engine. I would like to get image from the browser and upload it to cloud storage.
the form:
<form action="http://myappId.appspot.com/test/uploadImage" method="post">
<input type="file" name="file" value='file'><br>
<input type="submit" value="Submit">
</form>
my server side:
class uploadImageTOCloudStorage(webapp2.RequestHandler):
def post(self):
image = self.request.get("file")
gcs_file=gcs.open(GCS_BUCKET_NAME+'testImage.png', 'w')
gcs_file.write(image.encod('utf-8'))
gcs_file.close()
self.response.write("succeed !")
the file saved in the cloud storage, but the problem that I couldn't download it, I got this error:
The file could not be opened, it may be damaged or user a file format that preview doesn't recognize !
what should I do ?
I don't want to use blobstore, because create_upload_url
will be active just for ten minutes.
解决方案
Could it be because you do not have a proper enctype="multipart/form-data"
for your form?
这篇关于如何通过应用程序引擎将图像上传到云存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文