From e77320fa5b8a760aaff99eae3f1b3dba8a9ab5c8 Mon Sep 17 00:00:00 2001 From: danra Date: Thu, 3 Jul 2014 01:57:15 +0300 Subject: [PATCH] Fixed #1378 - Before validating an in-memory image file, seek to the beginning of the file. This is required to in case the same file is validated more than once. Currently, the same image file is validated twice when uploading an ImageField through the browser API - once when creating the model object, and once when rendering the HTML response. --- rest_framework/fields.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 6caae9242..8e5432627 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -1004,7 +1004,8 @@ class ImageField(FileField): if hasattr(data, 'temporary_file_path'): file = data.temporary_file_path() else: - if hasattr(data, 'read'): + if hasattr(data, 'read') and hasattr(data, 'seek'): + data.seek(0) file = BytesIO(data.read()) else: file = BytesIO(data['content'])