Skip to content

FileField representations should return URLs, not paths. #1368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
flisky opened this issue Jan 20, 2014 · 6 comments · Fixed by #1800
Closed

FileField representations should return URLs, not paths. #1368

flisky opened this issue Jan 20, 2014 · 6 comments · Fixed by #1800

Comments

@flisky
Copy link
Contributor

flisky commented Jan 20, 2014

FileField (and the ImageField) only show its name currently, rather than the storage url.

AFAIK, name is the string stored in the db; path is the MEDIA_ROOT + name; url is the MEDIA_URL + name.

Only found the same question on the ML. I think it would be convenient if we made this change.

Any thought on this?

@tomchristie
Copy link
Member

Would like to see this, tho it's not behaviour that we can just arbitrarily change for existing users.
I'm also not sure if this should be the default, optional, or link to a snippet/repo implementing this or demonstrating how to achieve this.

@nournia
Copy link

nournia commented Apr 5, 2014

I think it is an obvious requirement. When client asks server for object data, apparently wants to use them. So, only working (absolute) url of file or image is useful.

@eftechnologies
Copy link

@fletchowns
Copy link
Contributor

Related discussion, but for ImageField: https://groups.google.com/d/msg/django-rest-framework/ldRP-y_s6bQ/weRniVgkynkJ

@tomchristie tomchristie changed the title FileField's to_native should return its url property FileField representations should return URLs, not paths. Aug 18, 2014
@tomchristie tomchristie added this to the 3.0 Release milestone Sep 29, 2014
@tomchristie tomchristie mentioned this issue Sep 29, 2014
94 tasks
@escaper01
Copy link

just pass request to your serializer and you are good to go
serializer = ReviewSerializer(data=data, context={'request': request})
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
@fletchowns @nournia @tomchristie @flisky @eftechnologies @escaper01 and others