0

I am building a web application based on Google App Engine using python; however I have seem to have hit a roadblock.

Currently, my site fetches remote image URLs from an external website. The URLs are placed in a list and sent back to my application. I want to be able to store the respective images (not the URLs) in my datastore; in order to avoid having to fetch the remote images each time as well as having to deal with broken links.

The solutions I have found online all deal with a user having to upload their own images. Which I tried implementing, but I am not sure what happens to an uploaded image (or how it gets converted into a blob) once the user hits the submit button.

To my understanding, a blob is a collection of binary data stored as a single entity (from Wikipedia). Therefore, I tried using the following:

class rentalPropertyDB(ndb.Model):
    streetNAME = ndb.StringProperty(required=True)
    image = ndb.BlobProperty(default=None) 

class MainPage(BaseHandler):
    def get(self):
        self.render("index.html")
    def post(self):
        rental = rentalPropertyDB()
        for image in img_urls:
            rental.image = urlfetch.Fetch(image).content
        rental.put()

The solution to this question: Image which is stored as a blob in Datastore in a html page is identical to mine, however the solution suggests to upload the image to the blobstore and uses:

upload_files = self.get_uploads('file')
blob_info = upload_files[0]

This confuses me because I am not sure what exactly 'file' refers to. Would I replace 'file' with the URL of each image? Or would I need to perform some operation to each image prior to replacing?

I have been stuck on this issue for at least two days now and would greatly appreciate any help that's provided. I think the main reason why this is confusing me so much is because of the variety of methods used in each solution. I.e. using Google Cloud Storage, URLFetch, Images API, and the various types of ndb.Blobstore's (BlobKeyProperty vs. BlobProperty) and etc.

Thank you.

Community
  • 1
  • 1
mathee
  • 163
  • 12

1 Answers1

1

Be careful with blob inside Models. A Model cannot be more than 1 Mo including the blobproperty.

If we listen Google, there is no good reason to use the blobstore. If you can, use Google Cloud Storage. It made to store files.

Maël
  • 259
  • 1
  • 11