I have a file on my server: "test file.dat" (without the quotes of course). The file resides in a folder called "data%20dir". Yes, the "%20" is literal. So the complete path of the file is "data%20dir/test file.dat".
I want to view this file using a CGI script. The CGI script is called "viewfile.cgi". I call the cgi with the path as a parameter. I tried in Chrome and in Firefox, but both do incorrect translation of the query string.
If I type this in my browser's address bar:
http://www.myserver.com/bin/viewfile.cgi?file=data%20dir/test file.dat
In my server logs, I see the browser translated it to
http://www.myserver.com/bin/viewfile.cgi?file=data%20dir/test%20file.dat
before sending it to my server. So the first %20 just stays that way, but the space in "test file.dat" is translated to a "%20". The server can't find the file because it obviously doesn't exist.
When I type this in my browser's address bar:
http://www.myserver.com/bin/viewfile.cgi?file=data%2520dir/test file.dat
my server log show a request for:
http://www.myserver.com/bin/viewfile.cgi?file=data%20dir/test%20file.dat
So again this fails because the file could not be found on my server.
No matter what I try, the browser incorrectly translates the query string. Am I doing something wrong or is this a bug (in both chrome and firefox)?
Related
We have a pretty standard file selector on our web page, defined like this:
<input type="file" multiple="" accept=".csv,.json,.zip,.jpg,.jpeg,.bmp,.png,.gif,image/*">
This works fine for selecting a local file, but we found that if the user pastes a URL in to the "file name" field, the browser (chrome and firefox tested) will download that URL to a temporary file and set the result of the file chooser to that temporary file.
It looks like the name of that temporary file is based only on the URL given; that is, a URL like http://server/path/download?id=123 will result in a name of "download", while a URL like http://server/path/123.jpg will result in a name of "123.jpg", regardless of any headers defined on the response (e.g. content-disposition).
So my questions:
Is this behavior documented somewhere? I couldn't find it in MDN.
Can this feature be disabled to only allow selection from the local file system?
Is there a way to control the file name other than the URL?
As it turns out, I think this behavior is actually coming from the operating system (windows 10), not the browser dialog, as I can reproduce the same behavior using other applications. For example, in Eclipse I can paste URLs in the file open dialog, and they open in Eclipse with the same naming scheme. I also tried on a few other OS's and, as expected, the dialog is provided by the OS so in some cases didn't even have a way to input a URL.
Is there a way to show non-ascii characters in Chrome console to be showed properly, i.e. without percent signs?
For example, I'm testing some local webpage. It have connection to three different javascript files. One of this files is located at D:\[some non-ascii-characters].
And so, for example if this file is missing, I will see in Chrome console something like:
GET file:///D:/2%20---%20%D1[here will be more percent-encoded characters] net::ERR_FILE_NOT_FOUND
So, I want to show the actual clean easy to read path, without percent-encoded %20 %D1 and so on.
Is there a way to fix it?
There isn't an option to convert and there probably won't be one. Since this is the actual URL requested by the network it is what is put into the console. Doing any conversion on this can be misleading as to what is actually being requested.
I`m writing a ASP.NET web page to receive a file from the user, using fileUpload, then calling an .exe file to create a HTML based on that file. The HTML contains the file name, file length, etc.
In the program, I used:
var proc = Process.Start(path, arg);
proc.WaitForExit();
and also:
while(!File.Exists("my file path"));
I tried using a physical path like "C:\myWesite\CreateHTML\new.HTML", also a URL like "Mywebsite\CreteHTML\new.html". Both of these should take me to the new page if I type them in the browser.
The file is there when I use Response.Redirect(). If not, then the while loop will go on forever and cannot continue to the Response.Redirect() command.
The problem is that, after the redirect, it threw a "404 - File or directory not found." error. But, after I refresh it, the new page works fine even though the URL is the same. So, every time I use the website, I need to refresh in order to see it.
I Also tried Server.Transer(), but it didn`t show me the right page.
I used another PC with IIS to work as the server. I develop the webpage on another PC using webmatrix.
I'm loading a html file hosted on the OS X built in Apache server, within that file I am linking to another html file in the same directory as follows:
<a href="2ndFile.html"><button type="submit">Local file</button>
This works. However (for reasons too lengthy to go into) I am experimenting using the file: scheme instead, however I cannot get anything to work. Here is how I am re-writing the above line using file:
<a href="file://192.168.1.57/~User/2ndFile.html"><button type="submit">Local file</button>
(192.168.1.57 is my current IP address)
Changing it to the following does also not work:
<a href="file://Name-Of-MacBookPro/~User/2ndFile.html"><button type="submit">Local file</button>
But the file cannot be found, how should it be specified using the file: scheme?
The file: URL scheme refers to a file on the client machine. There is no hostname in the file: scheme; you just provide the path of the file. So, the file on your local machine would be file:///~User/2ndFile.html. Notice the three slashes; the hostname part of the URL is empty, so the slash at the beginning of the path immediately follows the double slash at the beginning of the URL. You will also need to expand the user's path; ~ does no expand in a file: URL. So you would need file:///home/User/2ndFile.html (on most Unixes), file:///Users/User/2ndFile.html (on Mac OS X), or file:///C:/Users/User/2ndFile.html (on Windows).
Many browsers, for security reasons, do not allow linking from a file that is loaded from a server to a local file. So, you may not be able to do this from a page loaded via HTTP; you may only be able to link to file: URLs from other local pages.
the "file://" url protocol can only be used to locate files in the file system of the local machine. since this html code is interpreted by a browser, the "local machine" is the machine that is running the browser.
if you are getting file not found errors, i suspect it is because the file is not found. however, it could also be a security limitation of the browser. some browsers will not let you reference a filesystem file from a non-filesystem html page. you could try using the file path from the command line on the machine running the browser to confirm that this is a browser limitation and not a legitimate missing file.
The 'file' protocol is not a network protocol. Therefore file://192.168.1.57/~User/2ndFile.html simply does not make much sense.
Question is how you load the first file. Is that really done using a web server? Does not really sound like. If it is, then why not use the same protocol, most likely http? You cannot expect to simply switch the protocol and use two different protocols the same way...
I suspect the first file is not really loaded using an apache http server at all, but simply by opening the file? href="2ndFile.html" simply works because it uses a "relative url". This makes the browser use the same protocol and path as where he got the first (current) file from.
I had similar issue before and in my case the file was in another machine
so i have mapped network drive z to the folder location where my file is
then i created a context in tomcat
so in my web project i could access the HTML file via context
For apache look up SymLink or you can solve via the OS with Symbolic Links or on linux set up a library link/etc
My answer is one method specifically to windows 10.
So my method involves mapping a network drive to U:/ (e.g. I use G:/ for Google Drive)
open cmd and type hostname (example result: LAPTOP-G666P000, you could use your ip instead, but using a static hostname for identifying yourself makes more sense if your network stops)
Press Windows_key + E > right click 'This PC' > press N
(It's Map Network drive, NOT add a network location)
If you are right clicking the shortcut on the desktop you need to press N then enter
Fill out U: or G: or Z: or whatever you want
Example Address: \\LAPTOP-G666P000\c$\Users\username\
Then you can use <a href="file:///u:/2ndFile.html"><button type="submit">Local file</button> like in your question
related: You can also use this method for FTPs, and setup multiple drives for different relative paths on that same network.
related2: I have used http://localhost/c$ etc before on some WAMP/apache servers too before, you can use .htaccess for control/security but I recommend to not do so on a live/production machine -- or any other symlink documentroot example you can google
I recently built a HTML and Javascript web application that opens specific folders throughout a network of accessible drives. This app works well when it is rendered in IE; however, the folder paths do not work in FireFox.
The following is an example of the path format that I am using to open the folders in IE:
{
window.open('\\\\Server-1\\Folder-1\\Folder-2');
}
The path actually has 4 backward slashes at the beginning and 2 bakcward slashes between each folder. It appears different when rendered.
When I run this app in FireFox, the window or new tab appears, but there is nothing rendered. I've manually entered the path and FireFox converts it to: file://///Server-1/Folder-1/Folder-2. Does anyone know what the correct syntax would be (i.e. window.open(?...))?
Here is something that might help you. It is considered a security risk by Mozilla.
http://kb.mozillazine.org/Links_to_local_pages_do_not_work
according to Daniel's link you need THREE forward slashes not FOUR for local paths...
Path Syntax
You also need to use proper URI syntax
for local file references. It is not
proper to enter an
operating-system-specific path, such
as c:\subdir\file.ext without
converting it to a URI, which in this
case would be
file:///c:/subdir/file.ext. In
general, a file path is converted to a
URI by adding the scheme identifier
file:, then three forward slashes
(representing an empty authority or
host segment), then the path with all
backslashes converted to forward
slashes.