Image Upload in Google App Engine
Asked Answered
R

2

2

I am working on a website where the user can upload a post relating to a location and then they can add two or three photos to go along with it. I understand how to do a basic upload with either the Datastore or the Blobstore but I want to link these photos to the post and to the user and then be able to display them in all pages connected to the post and the user.

That is the general idea but to be more specific I am trying to figure out if it would be easier to just to give the post entities 3 db.blob attributes and take a little hit on higher data costs or if it is doable to link the Blobstore entities with my Datastore entities.

Rebec answered 12/9, 2012 at 4:29 Comment(0)
S
5

That's what BlobReferenceProprty is for. You can add a reference to a blob into model which seems to be what you want.

Sabbat answered 12/9, 2012 at 5:15 Comment(5)
Note that this is a reference to BlobInfo, which only exists if blob was upload via upload handler. BlobInfo is not created if file is saved to blobstore via file api: developers.google.com/appengine/docs/python/blobstore/…Phototherapy
Ummm - no. BlobInfo should be being created when the file is finalized. If not, it's a bug and an issue should be opened on the tracker.Sabbat
Hmm, it seems so. We have thousands of blobs created via FileService API, but no __BlobInfo__ entities in the database. I can pass you our appid if you care to check.Phototherapy
My bad. I was relying on Datastore Viewer, where __BlobInfo__ is not shown. If I try to retrieve them they are there (via BlobInfoFactory or via key query).Phototherapy
@StuartLangley Would I be able to have a ListProperty and list references to many blobs in just one attribute?Rebec
P
2

Here is a full example of uploading photo and associating it to user.

To associate users and photos it uses creates class UserPhoto that links user ID and photo blob keys.

Phototherapy answered 12/9, 2012 at 5:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.