#6009: Error while upload file with non-english filename.
-----------------------+----------------------------------------------------
Reporter: bear330 | Owner: nobody
Status: new | Component: Internationalization
Version: SVN | Keywords:
Stage: Unreviewed | Has_patch: 0
-----------------------+----------------------------------------------------
Upload a file using newforms I will get a UploadedFile object which
contains filename and content for uploaded file.
If I upload a file with english file name ('abcd.jpg'), everything is
right.
But if not (for example: ''''中文.jpg'''', when I assign the UploadedFile
object's filename to ImageField or FileField in a model and save it, I
will get a UnicodeDecodeError.
This is because the '''django.http.parse_file_upload will treat filename
as 'str' object not 'unicode' object.'''
I must do this manually to avoid this bug:
'''filename = uploadedFileObj.filename.decode('utf8')'''
After that, UnicodeDecodeError will not happen again, but the FileField's
value in database will be '.jpg'.
OH! terrible! That is because the django.utils.text.get_valid_filename do
this:
'''re.sub(r'[^-A-Za-z0-9_.]', '', s)'''
'''This will be good in english file name, but not in other languages.
After the re.sub, '中文.jpg' => u'\u4e2d\u6587.jpg' will be u'.jpg'.'''
For me, this is very serious problem.
At this time, I can fix that by doing decode('utf8') and override
get_valid_filename manually.
But I hope this bug will be fixed by django officially.
Thanks for your effort. :)
--
Ticket URL: <http://code.djangoproject.com/ticket/6009>
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
-~----------~----~----~----~------~----~------~--~---