diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 41d6105ca..5e3d7b66c 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -1435,6 +1435,7 @@ class FileField(Field): self.allow_empty_file = kwargs.pop('allow_empty_file', False) if 'use_url' in kwargs: self.use_url = kwargs.pop('use_url') + self.url_prefix = kwargs.pop('url_prefix', api_settings.UPLOADED_FILES_URL_PREFIX) super(FileField, self).__init__(*args, **kwargs) def to_internal_value(self, data): @@ -1465,6 +1466,8 @@ class FileField(Field): # If the file has not been saved it may not have a URL. return None url = value.url + if self.url_prefix: + url = self.url_prefix + url request = self.context.get('request', None) if request is not None: return request.build_absolute_uri(url) diff --git a/rest_framework/settings.py b/rest_framework/settings.py index 3f3c9110a..988656651 100644 --- a/rest_framework/settings.py +++ b/rest_framework/settings.py @@ -112,6 +112,7 @@ DEFAULTS = { 'COMPACT_JSON': True, 'COERCE_DECIMAL_TO_STRING': True, 'UPLOADED_FILES_USE_URL': True, + 'UPLOADED_FILES_URL_PREFIX': None, # Browseable API 'HTML_SELECT_CUTOFF': 1000,