使用Django选择上传文件的文件名 [英] Choose the filename of an uploaded file with Django
问题描述
我正在上传图像(由FileField表示),并且在上传文件时需要重命名这些文件。
I'm uploading images (represented by a FileField) and I need to rename those files when they are uploaded.
我希望它们的格式如下:
I want them to be formated like that:
%d-%d-%s。%s%(宽度,高度,md5哈希,original_extension)
我已经阅读了文档,但是不知道是否需要编写自己的FileSystemStorage类或FileField类,或者...?一切都如此链接,我不知道从哪里开始。
I've read the documentation but I don't know if I need to write my own FileSystemStorage class or my own FileField class or ... ? Everything is so linked I don't know where to start.
推荐答案
您不需要编写自己的FileStorage类或
You don't need to write your own FileStorage class or anything that complicated.
File / ImageFields上的 upload_to参数可以采用一个函数,该函数返回要使用的路径/文件。
The 'upload_to' parameter on File/ImageFields can take a function that returns the path/file to use.
如何解决此问题此处
这篇关于使用Django选择上传文件的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!