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.

clifgray
  • 4,313
  • 11
  • 67
  • 116

2 Answers2

5

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

Stuart Langley
  • 7,044
  • 1
  • 20
  • 20
  • 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: https://developers.google.com/appengine/docs/python/blobstore/overview#Writing_Files_to_the_Blobstore – Peter Knego Sep 12 '12 at 05:29
  • 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. – Stuart Langley Sep 12 '12 at 07:14
  • 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. – Peter Knego Sep 12 '12 at 09:08
  • 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). – Peter Knego Sep 12 '12 at 09:39
  • @StuartLangley Would I be able to have a ListProperty and list references to many blobs in just one attribute? – clifgray Sep 12 '12 at 22:25
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.

Peter Knego
  • 79,991
  • 11
  • 123
  • 154