"Upload a valid image. The file you uploaded was either not an image
or a corrupted image."
In my view I am trying to read image file content:
image = self.request.FILES.get('image')
if image:
content = "".join(image.chunks())
Validation error doesn't occur if I comment line with image.chunks(), also
it isn't showed if I remove
"django.core.files.uploadhandler.MemoryFileUploadHandler" from
FILE_UPLOAD_HANDLERS setting.
So the reason could be in file object created by MemoryFileUploadHandler
(InMemoryUploadedFile).
My guess was it could be that after read there is no call file.seek(0)
which set file reader pointer to the begging of the file.
It could be ImageFile.to_python assumes that pointer set to the beginning.
In ImageField.to_python I have added
data.file.seek(0)
before
file = StringIO(data.read())
and I haven't got image validation error after that.
Is it proper behavior? Or ImageField shouldn't assume that file haven't
been read? Or InMemoryUploadedFile should call file.seek(0) after chunks
iterator ended its work?
--
Ticket URL: <https://code.djangoproject.com/ticket/20948>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
You are supposed to call `image.seek(0)` yourself after you read from it.
That said, it would be intresting to know why it works for
`TemporaryUploadedFile`
--
Ticket URL: <https://code.djangoproject.com/ticket/20948#comment:1>
* owner: nobody => sduveen
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/20948#comment:2>
* status: assigned => new
* owner: sduveen =>
--
Ticket URL: <https://code.djangoproject.com/ticket/20948#comment:3>
* status: new => closed
* resolution: => invalid
--
Ticket URL: <https://code.djangoproject.com/ticket/20948#comment:4>