Why does file: protocol has 3 (back)slashes in this URL?
file:///C:/Users
(C:/Users is the path name of this URL.)
How does an URL parser handle it?
I thought the last slash of these 3 slashes could mean 'path', I put a host name before declaring it, like
file://domainname.extension/C:/Users
but JavaScript's URL parser ignores this domain name.
To make things easier to understand, here file:// is the protocol and / is the root directory.
And later occurring terms are subdirectory, as in http://google.com: here http:// is the protocol and google.com is the root directory.
This is a URI scheme, typically used to retrieve files from within one's own computer.
For more details, see https://en.wikipedia.org/wiki/File_URI_scheme
Related
We're trying to pull files and folders from the locker, but the command (/d2l/api/le/(D2LVERSION: version)/locker/myLocker/(string: path)) doesn't like spaces in the file or folder name. It returns either Bad Request or Invalid Token depending on how we attempt to handle the spaces on our end (i.e. string replace with %20).
How would we retrieve files/folders with spaces in the name?
I can think of some possible problems you're encountering.
When you provide the API path to your D2LUserContext object, you need to pass in only the API path, with internal spaces, not escaped characters. So, a proper route to a file named test file name might look like this:
/d2l/api/le/1.0/locker/myLocker/firstFolderBelowRoot/test file name
to create the authenticated URL for this, you'd invoke
yourD2LUserContext.createAuthenticatedUri('/d2l/api/le/1.0/locker/myLocker/firstFolderBelowRoot/test file name', 'GET')
That would fashion an authenticated URL you can use to fetch that file named test file name from your locker. To fetch its containing folder:
yourD2LUserContext.createAuthenticatedUri('/d2l/api/le/1.0/locker/myLocker/firstFolderBelowRoot/', 'GET')
Note that when you want to identify a folder in the locker, the path parameter must end with a trailing slash. (If you're trying to fetch a folder, and you don't have the trailing slash, that might be a source of your issue.)
Once you have that URL, you'll need to use some sort of HTTP library to actually make the call. Our internal PHP devs have recommended using HttpRequest rather than cURL with PHP. Most notably, the URL you should make the call with should preserve the space in the file or folder name in the path component of the URL.
When I test against a 9.4.1 instance using the Python client to do fetches/puts from the locker, or to generate URLs using the user context object and then feeding those URLs into a browser, things seem to work fine. Testing against a 10.0.0 test instance using the Python client also seems to be working.
I can't understand the benefit(s) that I can get from Url.Content() method in ASP.NET MVC. For example, you see src='#Url.Content("~/Contents/Scripts/jQuery.js")'. Why should I use it? What reasons might exist for using it? What benefits, advantages, etc. over using plain old simple references like src='/scripts/jquery.js?
Update: Based on the answers, I'd like to know if there is any other reason for using it, other than handling virtual folders? Because I haven't seen using virtual applications that much (which of course doesn't mean that it hasn't been used that much).
Usually, your web application is published as: www.yoursite.com/. The ~ character matches the root of the site /.
However, if you publish your site withing a virtual directory www.yoursite.com/mywebapp/, the the ~ character would match "/mywebapp/".
Hard-coding Urls with "/" character would cause wrong page references.
Mapping virtual paths is it's only purpose.
If you do not ever need to map them and are sure your app or it folders will not sit under other apps then it won't serve you any purpose.
From the docs note if you don't use ~ you get no change in the result anyways:
"Remarks
If the specified content path does not start with the tilde (~) character, this method returns contentPath unchanged.
"
It is usefull if your applications root path is not the root path of your server. Url.Content("~/") returns the root folder of your application.
In a class such as NSFileManager there are 2 versions of practically every method. One for paths and one for URLs. What's the difference? And what's the best practice for converting a URL to a path.
path is location of a resource (file/directory) in a file system. Just like iOS File System, other environments file system can be Windows file system, Unix etc. Path can have spaces like /docs/random doc/. (between random and doc)
URL is is a reference to a resource anywhere (file system, web HTTP, FTP etc). URL can not have spaces like path.
Web URL: http://stackoverflow.com/
file URL: file://localhost/Users/username/docs/random%20docs/
path for above mentioned file URL: /Users/username/docs/random%20docs/
in layman terms:
URL = protocol (http, file etc) + host (domain name or IP or localhost) + path
URL includes the protocol being used (http:// etc). Path doesn't or doesn't need at least.
Example Mercurial URL: ssh://myhost//path/to/repo
Why two slashes? The hostname is already specified. Why it does not work like http://myhost/path/to/page where only one slash is sufficient?
See this url, which says this:
path is relative to the remote user's home directory by default.
Use an extra slash at the start of a path to specify an absolute path:
Usually a URL is formed in the following way: scheme://user#host:port/path, with the user# and :port part being optional. This means the first / is the separator between the host part and the path part: it is not part of the path.
Then the path can either be absolute (starts with a /) or relative to the home directory of the user (no /).
This is just a reminder that the paths used by rsync or scp are not urls.
I'm almost finished developing my large project, however I would love it if I could make it so instead of having the users profile pages at: http://example.com/profile/username/USERNAME
(i'm currently using .htaccess to rewrite the GET data into forward slashes and profile(.php) being read as just 'profile' profile.php also parses the url correctly to retrieve the GET data)
But it would be some much better if I could do it so that it's like http://www.example.com/USERNAME (preferred) or http://www.USERNAME.example.com
Any ideas or resources?
Thanks,
Stefan
In your .htaccess in the root, add
RewriteRule ^/([^/]+)/? /profile/username/$1
This matches paths that don't include a slash (so no directories in the path) and suffixes the path to /profile/username/. The path can include an optional final slash.
(+1 for the comment about namespaces - it's a little dangrous having usernames in the root of your site. I've tried to limit the impact of this by only giving out the namespace comprising a single directory. Paths with multiple directories will be handled as normal.)