Django文件上传:路径和文件名 [英] Django FILES upload: path and filename
问题描述
当Django服务器接收到上传的文件时,可以使用UploadedFile.name
When an uploaded file is received by the Django server, its name can be read using UploadedFile.name
读取其名称。如果多部分数据内容中的文件名包含一个路径, :'/ a / b / c',UploadedFile.name似乎包含'/ c'。如何检索完整路径而不仅仅是文件名。
If filename in the multipart-data content contains a path like: '/a/b/c', UploadedFile.name seems to contain '/c' . How can I retrieve the full path and not just the file name.
谢谢。
Laurent Luce
Laurent Luce
推荐答案
你不能。许多浏览器不会发送整个路径,作为防止信息泄露的安全措施。
You can't. Many browsers won't ever send the whole path, as a security measure to prevent information leakage.
还没有什么关于文件和路径命名约定用户的电脑,所以你很少可以用提交的名字。不要做任何依赖于提交的文件名的东西。
What's more you know nothing about the file and path naming conventions in force on the user's computer, so there is little you can do with the submitted name. Don't do anything that relies on a submitted filename.
这篇关于Django文件上传:路径和文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!