简体   繁体   中英

How to handle post request in google cloud endpoints?

  @endpoints.method(InputClass,OutputClass,
                          path='apipath', http_method='POST',
                          name='something.apiname')

and my input class is

class InputClass(messages.Message):
    var1 = messages.StringField(1)
    var2 = messages.StringField(2)
#Code to store image data

From the above code a service is created that is called from the form with form data. Now on the form there is file field in which user uploads a photo. Now all other form data will get stored in the input class but i don't know how to store image in input class. I mean what would be the message field to store the image data.

Convert the photo to Base64 and send it as a String value. You can find lots of examples how to do this eg Base64 encoding in Python 3

If the photo is large you have to use Blobstore. More about uploading files to blobstore here . Once the photo is uploaded to the Blobstore you keep track of its blobKey . You can fetch or delete the photo from the Blobstore using the blob key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM