django-rest-framework-mongoengine
django-rest-framework-mongoengine copied to clipboard
ImageField returns Null
Excuse me, Did you fix this ImageField issue? I sill have same issue even though I am using up-to-date source.
In my Mongodb, image field has been well inserted like ("image_file" : ObjectId("57ff54681d41c8bf44ddc047") However, when I use the DocumentSerializer, it returns "image_file": null.
Looks like DocumentSerializer class doesn't support ImageField & FileField
Not well supported or untested:
FileField
ImageField
BinaryField
@umutbozkurt
https://github.com/umutbozkurt/django-rest-framework-mongoengine/blob/2067a702837a2387c7c1c01b2d296b44a53d25b5/rest_framework_mongoengine/serializers.py#L88
if you don't resolve this issue asap, is there any alternative way to use ImageField ? I need this feature ASAP please.
Please provide your code? I am using this field in my project and it works quite well.
@jcodebrain There is a nice unit-test for ImageField in DRF-Mongoengine test suite and it passes successfully. See: https://github.com/umutbozkurt/django-rest-framework-mongoengine/blob/master/tests/test_files.py#L58
I've got the same problem. And I read the image from girdFS myself: override the to_representation of your Serializer just like:
def to_representation(self, obj): data = super(BookSerializer, self).to_representation(obj) imageFileField = obj.bookCoverImage if imageFileField != None: imageFile = imageFileField.read() if imageFile != None: # client needs the base64 imageString = base64.b64encode(imageFile) data.update({'bookCoverImage':imageString}) return data
@iKeepWalking @jcodebrain Ok, I'll take a closer look.
@iKeepWalking
So, currently DRF-ME's FileField returns grid_id instead of a hyperlink to the file content (that's what DRF's FileField does and probably what we should). @qwiglydee What do you think about this, Maxim?
I'm not sure if streaming a base64-encoded file back is a good solution. Currently, I'm googling a way to return a url to file content with Mongoengine, as we can't rely upon django's media mechanism for this.
@jcodebrain As for nulls, returned by ImageField - I don't see them. Did you insert the image manually with pymongo or Mongoengine? Or with DRF-ME? Cause for me DRF-ME-inserted file works fine.
I might be very busy until Wednesday, but on Thursday I'll be right here to help.
@BurkovBA I inserted the image with django-mongoengine .. is there any progress to solve this issue?
The image file was saved well in the mongodb's chuck collection but only issue when retrieving the image file. and I can deliberately get grid_id but I want to get a hyperlink to display the image properly instead. Could you make it possible? or is there any solution?even temporarily
@jcodebrain Hi!
No, I didn't make any progress to solve it, sorry.
I was unable to figure out, how to serve this file as a hyperlink. If you're serving a file in normal DRF, it is stored in filesystem and served by mediaserver, so that in DRF you just return a hyperlink.
May be, I should create a specific endpoint, which just gets the file from database and returns that file in response like this: http://stackoverflow.com/questions/25449946/django-rest-framework-return-file?
I created an endpoint in my project finally.
can we know how ?
can we know how ?
Two years later, no one knows how. Three years later, still no one knows how.
no one solves this issue !!?
这是来自QQ邮箱的假期自动回复邮件。 您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。