def get_upload_to(self, filename):
filename = self.file.field.storage.get_valid_name(filename)
# do a unidecode in the filename and then
# replace non-ascii characters in filename with _ , to sidestep issues with filesystem encoding
filename = "".join((i if ord(i) < 128 else '_') for i in unidecode(filename))
# Truncate filename so it fits in the 100 character limit
# https://code.djangoproject.com/ticket/9893
if self.folder:
full_path = os.path.join(self.folder.path, filename)
else:
full_path = os.path.join(IMAGES_FOLDER_NAME, filename)
if len(full_path) >= 95:
chars_to_trim = len(full_path) - 94
prefix, extension = os.path.splitext(filename)
filename = prefix[:-chars_to_trim] + extension
if self.folder:
full_path = os.path.join(self.folder.path, filename)
else:
full_path = os.path.join(IMAGES_FOLDER_NAME, filename)
return full_path
评论列表
文章目录