On saving a resource with a file field, tastypie overwrites the filename with whatever the url for that file was when using external storage (i.e. django-storages).
The tastypie.fields.FileField dehydrate gets the field url after is calls convert(). For example, a filed with file.txt would return https://example.com/file.txt?token=ABC.
def convert(self, value):
...
try:
# Try to return the URL if it's a ``File``, falling back to the string
# itself if it's been overridden or is a default.
return getattr(value, 'url', value)
...
This is what you would expect on a GET. But when the file is saved (PUT, PATCH), tastypie will save that URL (https://example.com/file.txt?token=ABC) to the field instead of the original value (file.txt) corrupting the data. Note that storing the URL is not an option because with services like S3 the URL has to be signed each time.
On saving a resource with a file field, tastypie overwrites the filename with whatever the url for that file was when using external storage (i.e. django-storages).
The
tastypie.fields.FileField
dehydrate gets the field url after is callsconvert()
. For example, a filed with file.txt would return https://example.com/file.txt?token=ABC.This is what you would expect on a GET. But when the file is saved (PUT, PATCH), tastypie will save that URL (https://example.com/file.txt?token=ABC) to the field instead of the original value (file.txt) corrupting the data. Note that storing the URL is not an option because with services like S3 the URL has to be signed each time.