How do I get the full path of a file from the upload object?
I’m afraid browsers don’t have access to the file paths of files uploaded from users’ machines for security reasons (here’s a StackOverflow answer about that).
(Media objects that come from Data Tables, Google Drive, or an external URL have a url
property.)
There may be another way of skinning this particular cat - what is it that you’re trying to achieve?
Thanks. I was just looking through my earlier versions. In those I was providing the files via a localhost server, so I had as much of the directory structure as I wanted to expose, based on where I started http-server. This gave me the illusion of knowing the path.
As to the use case, in RDF everything is a resource with a unique id. Usually a URI. When you read from disk you could have multiple files with the same name. So I wanted to make it unique to the users machine at the very least. I have two routes I can follow: provide an explicit baseURI input for the user to choose how they want to identify the resource; or make up some or (no) id. Currently I am simply letting it go through as file:///filename
.
I have two routes I can follow: provide an explicit baseURI input for the user to choose how they want to identify the resource; or make up some or (no) id.
Here are some ID ideas from me - I’d probably go with the last one.
- Append an incrementing number to the filename if you have multiple files with the same name
- Append a randomly generated number with sufficient entropy. Or a multi-word phrase like Anvil’s default public app domain names.
- Name the file as a UUID! Guaranteed not to collide but not very memorable. But you could store the UUID as part of a separate
URI
field and allow thefilename
field to be non-unique. - Append a hash of the file to the filename? That way it would be calculable from the contents of the file and unlikely to collide.