Retrieving images from GridFS using django-tastypie-mongoengine

291 views
Skip to first unread message

Hélio Miranda

unread,
May 8, 2013, 7:16:33 AM5/8/13
to django...@googlegroups.com

I have a project in Django, and I'm using mongoengine to save images into a Mongo database using GridFS.

All ok so far, but the problem is... when trying to retrieve the images via http request, with a REST API made with django-tastypie-mongoengine, I get back a json object like this:

{"file": "<GridFSProxy: 516ed7cf56ba7d01eb09f522>", "id": "516ed7cf56ba7d01eb09f524", "resource_uri": "/api/v1/movie/516ed7cf56ba7d01eb09f524/"}

Does anybody know how could I get the file from GridFS via http request?

Thanks!

Ryan Nowakowski

unread,
May 9, 2013, 1:52:30 AM5/9/13
to django...@googlegroups.com
Are you using mongoengine's GridFSStorage?

Hélio Miranda

unread,
May 9, 2013, 4:50:18 AM5/9/13
to django...@googlegroups.com
No, I'm not using GridFSStorage.

I was just using mongoengine, with FileField field.

To get the image have to use GridFSStorage?
How to use it?

Ryan Nowakowski

unread,
May 15, 2013, 3:12:45 PM5/15/13
to django...@googlegroups.com
GridFSStorage[1] is a Django storage backend[2]. You can override the
default storage backend for FileField[3] to use GridFSStorage[4] or set the
default storage for all FileFields to be GridFSStorage.

[1] http://docs.mongoengine.org/en/latest/django.html#storage
[2] https://docs.djangoproject.com/en/1.5/ref/files/storage/
[3] https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.FileField.storage
[4] https://docs.djangoproject.com/en/dev/topics/files/#file-storage
Message has been deleted

Hélio Miranda

unread,
May 16, 2013, 4:51:34 AM5/16/13
to django...@googlegroups.com
But then so was not save in mongodb but in a folder on the server right?
And then as these associated files to records that are in mongodb?

And I'm not using Models, I am using as mongoengine:

class Movie(mongoengine.Document):
    MovieTitle = StringField(max_length=100, required=False)
    MovieCover = FileField()
    ...
Reply all
Reply to author
Forward
0 new messages