Phil Stahlfeld
Phil Stahlfeld

Reputation: 71

GAE upload image to cloud endpoints [Python]

I'm fairly new to GAE and I was wondering how people normally upload images to be stored in Blobstore SPECIFICALLY USING ENDPOINTS. I have seen that there are a lot of examples for apps that don't use endpoints, but nothing for endpoints. My idea was to serialize an image on the client side and send it in a messages.BytesField message to the server to store it in Blobstore. Two questions:

  1. Is this the correct method for uploading images to endpoints?
  2. How do you take the BytesField from the message and store it in Blobstore?

Any help would be appreciated :)

Upvotes: 0

Views: 746

Answers (2)

vertazzar
vertazzar

Reputation: 1053

you would have to do something like

import cloudstorage as gcs

with gcs.open('bucketname/filename', 'w') as f:
  f.write(blob)

blobkey = blobstore.create_gs_key(gc_object_name='bucketname/filename')

print images.get_serving_url(blobkey)

however be careful when sending large datasets to appengine, it has 32 mb request size limit, 60 seconds deadline when processing, and when reading sent blobs it can take memory and your instance might restart, since they have limited amount of ram based on configuration in console.

Upvotes: 0

Peter Knego
Peter Knego

Reputation: 80340

It used to be possible to upload files programmatically to Blobstore, but this is now deprecated.

However, you can programmatically upload files to Cloud Storage and then serve them via Blobstore API.

So:

  1. Yes this approach is possible (so it's also correct)
  2. See links above on how to create a file in Cloud Storage

Upvotes: 2

Related Questions