Upload file to unicode filename

I have a file with a unicode name (e.g. Chinese characters). I get a UnicodeEncodeError. I am using postgres database with utf8 and django development server on ubuntu lucid 64. What am I missing? I do the following, where filename is the unicode file name in models.py:

def get_upload_path(instance,filename):
    return filename # Unicode error if filename has non latin 1 characters

class Kind (models.Model):
    style = models.ForeignKey(Style)
    kind_file = models.FileField(upload_to=get_upload_path)

from the shell:

enter image description here

+3
source share
2 answers

I believe the problem is with string formatting. In python2, it is automatically converted between a type str(which is a series of bytes) and unicodewhich is an abstract series of unicode encodings.

I assume yours filenameis of type unicode.

"tmp/%s/%s" , python unicode str . , ascii, .

return temp2 filename , .


, , . , . , decode unicode encode, . unicode (u"" "").

, tempN.

+3

All Articles