how to upload image to the cloud storage via app e

2019-02-15 17:01发布

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.

1条回答
甜甜的少女心
2楼-- · 2019-02-15 17:31

Could it be because you do not have a proper enctype="multipart/form-data" for your form?

查看更多
登录 后发表回答