tags:

views:

369

answers:

2

This question is in terms of a RESTful ROA (Resource-Oriented Architecture). A resource on the Web has a URL (or URI if you prefer), for instance http://myserver.com/me.jpg.

You can get a file on the local (Windows) machine like this: file:///C:/MyPictures/me.jpg. This is not exactly a "Universal" Resource Identifier; it doesn't work right if you try it on a different machine. On your machine this may be a picture of you instead of me.

Suppose I want to design an application where files can be copied to a web service. Other users on other machines can download them from the web service, but if you are using it from the original machine they are fetched from the local file system for speed.

Is there any concept of a URI that refers to a file on a particular machine if it happens to be the local machine? Is there any concept of a URI for a particular machine? IP address isn't enough; my machine's IP address is 192.168.0.102 and yours may be too.

I would like to store a number of locations for the photo as first choice, second choice etc. First choice = file:///C:/MyPictures/me.jpg but only if the local machine is the machine it came from; second choice = http://myserver.com/me.jpg.

Another way of stating the same question: this machine is unique, and the file at C://somedir/somefile.jpg is unique. Does it have a unique address? An address that would yield either "No Route to Host" or the correct file, depending on where you requested it from?

+1  A: 

Is there any concept of a URI that refers to a file on a particular machine if it happens to be the local machine?

Let's follow the logic. How is this to be determined? The URI absolutely must contain a name which uniquely identifies the machine.

Hence, your machine must be identified by a publicly registered name. You have clearly identified that a private IP address is insufficient.

So, the answer is:

  • Your machine must be publicly accessible (via proxy if behind a firewall) by a publicly identified name.

  • That name must also resolve directly to your machine (not by a firewall) if you want efficiency in the "local running case".

Setting this up is machine dependent. But assuming you're behind a NAT firewall which supports virtual server proxies...

  1. Register the unique name in the appropriate DNS server, have it resolve to the publicly-facing IP.

  2. Set up a virtual server on your firewall proxying back to your internal address.

  3. Set up a web-server on your local machine.

  4. Ensure that your local machine itself is configured (in /etc/hosts or Windows equivalent) to map that public address to your 192.168 address.

That basically does it. Impossible to imagine how anything else would. No, it's not possible for a single URI to be defined as "Try file:// in this case, or default to http://". The very definition of URI is a single scheme, as described here:

http://en.wikipedia.org/wiki/URI_scheme#Generic_syntax

the.jxc
The machine must be addressible but does not have to be publicly accessible. Like the gold in Fort Knox, you know where it is even if you can't get to it. You don't need a local web server if you use the "file" scheme. For instance I can access "file://blackbeauty/shareddocs/myfile.txt" but only because shareddocs is the name of a file share. "blackbeauty" is unique on my network but not universally. So this is a possible but not totally satisfactory way to do it.
Mark Lutton
A: 

You're both correct and incorrect. While two computers can have the same name or the same ip address within a network segment, they only exist within that network.

If you want to uniquely identify a file and a machine, then file://blackbeauty.mydomain.org/c:\myfile.txt is perfectly acceptable, in the sense that the blackbeauty name is "owned" by mydomain.org.

So you will need a way to address machines in FQDN if you want the URL to be resolvable.

serialseb
The URL file://blackbeauty.mydomain.org/c:/myfile does not need to be resolvable from anywhere except blackbeauty.mydomain.org itself. Being resolvable elsewhere on the local network is good but not required. So this is a good solution where there is a domain name that "owns" the machine.I'm still looking for a way to uniquely identify a machine that is not addressible, or even necessarily identifyable. All I need to know is: is John connecting from the same computer today as yesterday? Cookies are a partial solution.
Mark Lutton
so you want an identifier for that machine that is constant over time, without a central authority?I'm afraid I really don't understand much what the issue with using file://machinename/c is. It is without central authority, is constant over time and you have no need for it to be used for anything but local resolving, as you mention you don't need it to be either addressible or identifyable.Cookies are server-issued persistence bags, if you already have access to the local machine why bother with it? Unless you refer to using a browser for local resolves?
serialseb