diff --git a/rest_framework/fields.py b/rest_framework/fields.py index ff6db703f..275c7a9a7 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -1198,8 +1198,12 @@ class FileField(Field): return data def to_representation(self, value): + if not value: + return None + if self.use_url: - if not value: + if not getattr(value, 'url', None): + # If the file has not been saved it may not have a URL. return None url = value.url request = self.context.get('request', None)