file.save crashes on unicode filename
|Reported by:||sylvain.lebon@…||Owned by:||nobody|
|Cc:||charette.s@…, lrekucki@…||Triage Stage:||Accepted|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I try to add a file into a FileField of one of my object.
The problem is I get a file with a unicode name with special characters.
name = (u'l\u2019\xe9cran.png').encode("utf-8")
now if I do
str1 = "%s%s"(MEDIA_ROOT, name)
'/home/oi/OIFS/Capture d\xe2\x80\x99\xc3\xa9cran 2012-01-24 \xc3\xa0 14.58.48.png'
and os.stat(str1) passes.
str2 = safe_join(MEDIA_ROOT, name)
str is then
u'/home/oi/OIFS/Capture d\u2019\xe9cran 2012-01-24 \xe0 14.58.48.png'
and os.stat fails.
The thing is file.save(name, content, False) uses safe_join and then os.stat.
Now I'm not sure if I should get the name in a different encoding but I don't seem to manage to get it right.
Change History (7)
comment:1 follow-ups: ↓ 4 ↓ 5 Changed 4 years ago by lrekucki
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
comment:6 Changed 3 years ago by claudep
- Component changed from File uploads/storage to Documentation
- Type changed from Uncategorized to Cleanup/optimization