save upload file with specify encode
|Reported by:||Owned by:||flyinflash|
|Has patch:||no||Needs documentation:||yes|
|Needs tests:||no||Patch needs improvement:||no|
# -*- coding: utf-8 -*- # in models.py def get_path(instance, filename): path = osp.join('uploads', '中文'.encode('utf8'), filename) return path class Files(models.Model): name = models.CharField(max_length=64) files = models.FileField(upload_to=get_path, storage=MyStorage)
Upload file with above code on Chinese version MS-Windows, it will get strange filename which contains unreadable characters.
I guess this problem associated with Chinese version MS-Windows using GBK encoding by default.
After read debug a long time and has read http://docs.djangoproject.com/en/dev/howto/custom-file-storage/, I think use custom storage which could specify save file with specify encode, such as GBK could fix my problem.
Django is a very very very good Web framework, I hope developers could add this feature, and please don't try to restrict user or down stream developers, thanks.
Change History (6)
comment:1 Changed 7 years ago by
|Owner:||changed from nobody to flyinflash|
|Patch needs improvement:||unset|
|Status:||new → assigned|