I am using a forms.FileField to have the user choose file to open. I need to know which path the user chose in addition to the filename. I can't seem to find that anyplace. I will be loading other files from the same path.
The path on the client (the user's computer) is not sent.
You cannot load files from the same path - unless you have some client side code (like a java applet or flash application) that has proper security permissions to open files on the client's computer, then send the files to your server over a TCP connection - which you don't.
So in summary, the file path on the client's computer is not available when using file upload fields, using any server side language.
For more information:
RFC 2388 (the specification)
How to get the file path from html input form
W3C Form Reference
Related
I use fileInput to upload one file which contains the paths and file names of multiple files on my local computer.
I would then like to use these file paths and upload them to the server directly without the user having to perform any more interaction.
So simply put how do I upload a file to the shiny server I already know its local path?
As noted on other cffile upload questions,
GetPageContext().formScope().getUploadResource("myFormField").getName()
is great for getting the filename on the server before actually doing the cffile (for Railo and Lucee - there's a different method for ColdFusion) but I noticed an interesting wrinkle: if the browser is IE then this returns the full source path including the filename. Firefox and Chrome on the other hand, return only the filename.
For my application I need the full path, but haven't been able to find that when the browser is FireFox or Chrome. If anyone has any ideas I would be most grateful!
(Expanded from the comments)
I am not familiar with the getUploadResource() function. However, looking over this related thread, it sounds like it returns file information submitted by the client. While there are recommended guidelines, ultimately the value received on the server is whatever the browser chooses to send. It is not something that can be changed or controlled by server side code. So if Firefox and Chrome return something different than IE, you are out of luck.
(As an aside, personally I have always found Internet Explorer to be a bit odd in this area. Traditionally browsers are restricted from certain file access operations for security reasons, unless a signed control is used. So you might expect those restrictions would prohibit a browser from submitting information about the structure of the client file system as well. In fact, most browsers do not submit path information with uploads, only a file name. Obviously, Internet Explorer chose to do things .. differently .. for whatever reason)
For my application I need the full path
Having said all that, why would you need the path from the client machine?
I want to save a file to a network server. Currently, I need to first save it locally, and then copy it to the server. The server supports ssh and ftp.
I would like instead to operate all directories and files in my GUI as if they were local paths, as follows:
Connect to the server, using ssh or ftp or tftp.
Then I click the get file button.
A FileDialog shows, displaying a drop-down list of all servers, while also including the local path.
When I choose a server, then list the server's directory, I can operate it as a local directory.
I know I can use QFileDialog in my QT project to open a file from local disk or save it, but can it do this?
Is there any way, when saving a file, to choose either to put it in the server or the local directory?
I'm making a django app to index my collection of local files (html, text, pdf, ... ) that I keep in diferent partitions and directories so I can search easily based on the name, date, title, etc of the files. It's like a advance locate, the unix utility. It generates a dynamic page with links for the files and in the case of the html files I should click and load the local file in the brower. The generated page contains links like:
Title of local file</li>
The problem is that when I click it does nothing, not even error messages. If I save this generated html page and open it in the brower directly it works fine. I think it doesn't work for security issues but I do not pretend to use it as a web app over the internet but as a local app. I am using the django development server. I know that django can serve static files putting them in a specific directory but this isn't what I need (the files are in multiple locations); I want to load the files in the browser as local files, not through the server. Can this be done?
Is there a way in django to make the "file:///C:/path/file.html" scheme work in the generated dynamic pages?
The problem had nothing to do with django but the browser (in my case firefox 4). Firefox doesn't allow to link to local files from remote sites for security reasons. I have to disable this security check for http://localhost:8000 and it worked. As the change only affects localhost it shouldn't be a security issue.This link explain how to do it:
http://kb.mozillazine.org/Links_to_local_pages_don%27t_work
Basically all you need to do is create a user.js file in your firefox profile folder with this:
user_pref("capability.policy.policynames", "localfilelinks");
user_pref("capability.policy.localfilelinks.sites", "http://localhost:8000");
user_pref("capability.policy.localfilelinks.checkloaduri.enabled", "allAccess");
If you use noscript you also have to change some configuration: NoScript Options ("Advanced -> Trusted -> "Allow local links").
Other browsers may have this security checks so you will have to do diferent changes accoding to the operating system and browser you use.
: is wrong. Use | instead.
Title of local file
I'm currently using django. And now I need to save a file uploaded by a user to another server which is not the one that serves the django application. The file will be saved to file system not the database. Could somebody tell me how to do this?
Default Django behavior is to save file on the filesystem, not the database itself).
You have several options how to do this, the simplest one is to have a filesystem exported from you "other" machine and mounted on the machine with the django application.
For the filesystem export you can use NFS, MogileFS or GlusterFS (which I'm using) or many more :). If you do not need real-time save&serve, simple rsync may be an option too.
Second option is to utilize existing django mechanisms StogareAPI. There are already available different storage backeds you can use and may be helpful for you (e.g. ftp).
This wont work out of the box, you need to have a mechanism(write some code) to queue the files that are uploaded through django application, then use a middleware(can be in python) to transfer files from queue to your file server. so flow is basically like this:
Accept the uploaded file via django app.
django app. writes the file info(its temporary path and name) to a queue
A middleware app reads the next file in queue.
The middleware app use some transfering protocol(sftp, scp, ftp, http etc...) to copy the file to file server.
Middleware app deletes the file from where django app is hosted so django server dont have a copy of the file.