#7812: read() in an InMemoryUploadedFile returns an empty string
----------------------------+-----------------------------------------------
Reporter: kratorius | Owner: nobody
Status: new | Milestone:
Component: Core framework | Version: SVN
Keywords: upload | Stage: Unreviewed
Has_patch: 1 |
----------------------------+-----------------------------------------------
If you try to access to .read() in an InMemoryUploadedFile object, you'll
get an empty string unless you don't call .seek(0) so it gets to the
beginning of the file.
To test, just write a model like this:
{{{
#!python
class TestModel(models.Model):
photo = models.ImageField(upload_to='test/',
validator_list=[validators.CustomValidator()])
class Admin:
pass
}}}
And this validator:
{{{
#!python
class CustomValidator(object):
def __call__(self, field_data, all_data):
print "Size: " + str(field_data.size)
print "Len: " + str(len(field_data.read()))
}}}
We get:
{{{
Size: 378054
Len: 0
}}}
Attached patch solves this issue.
--
Ticket URL: <http://code.djangoproject.com/ticket/7812>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---