Django文件上传:路径和文件名 [英] Django FILES upload: path and filename

查看:135
本文介绍了Django文件上传:路径和文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆