如何以 utf-8 格式保存名称的文件

how can save file with names in utf-8

我需要用 utf-8 保存文件 names.but 当我这样做时 django 错误:

UnicodeEncodeError at /uploaded/document/ 'فیلتر.png'
'ascii' codec can't encode characters in position 55-59: ordinal not in range(128)

虽然,我的文件字段喜欢它:

# -*- coding: utf-8 -*-
def get_path(instance, filename):
    return u' '.join((u'document', filename)).encode('utf-8').strip()

class Document(models.Model):
    file_path = models.FileField(verbose_name='File', upload_to=get_path,
                                 storage=FileSystemStorage(base_url=settings.LOCAL_MEDIA_URL))

我该如何解决? 我用tastypie api上传文件。

我的问题在这里得到了回答: https://itekblog.com/ascii-codec-cant-encode-characters-in-position/#The_Code

我应该更改 apache2 编码: /etc/apache/envvars

导出 LANG='en_US.UTF-8' 导出 LC_ALL='en_US.UTF-8'