简体   繁体   English

Django Upload文件获取全名和文件路径

[英]Django Upload file get full name and file path

I'm tinkering around with cloud storage api's and need help getting the full file name from an upload form on Django. 我正在修改云存储API,并且需要帮助来从Django的上传表单中获取完整的文件名。 I currently can let the user choose a file, "file.txt" from any directory, and can get the name through 我目前可以让用户从任何目录中选择文件“ file.txt”,并可以通过以下方式获取名称

for file in request.FILES.getlist('file'):
    print file.name `

However I want the full file path, something more like 'home/user/documents/file.txt' 但是我想要完整的文件路径,更像是'home/user/documents/file.txt'

Is this possible and how would I get the full name? 这可能吗,我怎么得到全名? I'm not looking to actually upload the file, just get the full path so that I can utilize dropbox/google drive api. 我不希望实际上传文件,只是获取完整路径,以便可以使用Dropbox / Google Drive API。

For reference here is my form : 供参考的是我的表格

class UploadFileForm(forms.Form):
    folder_name = forms.CharField(max_length = 300)
    title = forms.CharField(max_length=50)
    file = forms.FileField(label='Select a file')

Thanks in advance. 提前致谢。

Browsers do not tell what directory the files come from. 浏览器不会告诉您文件来自哪个目录。 They do not even give that information to the scripts on the page. 他们甚至不将该信息提供给页面上的脚本。

When a user uploads a file, you may know: 用户上载文件时,您可能会知道:

  • Its basename. 它的基名。
  • Its size. 它的大小。
  • Its type (usually guessed from extension). 它的类型(通常从扩展名中猜测)。
  • Its modification time. 它的修改时间。

This is all you will get, regardless of whether you access the information straight from the browser's <input> element, or wait for it to POST it. 这一切,你会得到的,无论你从浏览器直接访问信息<input>元素,或者等待它POST它。

You may also turn this answer the other way around: if you really need to be able to post the full path of the file, you need to develop a client-side application that will send it. 您也可以反过来回答此问题:如果确实需要发布文件的完整路径,则需要开发一个将发送该文件的客户端应用程序。 It could be a standalone executable, a browser addon/app, or a Java applet, whatever as long as it runs outside of the webpage sandbox. 它可以是独立的可执行文件,浏览器插件/应用程序或Java小程序,只要它在网页沙箱外部运行即可。

I do not use dropbox, but I believe you need to download and install some additional software to use it. 我不使用保管箱,但我相信您需要下载并安装一些其他软件才能使用它。 That's how it would access the full path of your files. 这样便可以访问文件的完整路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM