0

I'm trying to get the absolute path to use as a static reference

<input type="file" onClick="getFilePath">

function getFilePath(e)
{
  console.log( e.target.files[0] );
}

but I'm getting only the name of the file..

for example if I need to open an image locally I need to provide the url

new ImageLayer({
            source: new Static({
              url: 'https://foo.bar.com/lorem/image.png',//Local path goes here
              projection: projection,
              imageExtent: extent
            })
          })
kriqo
  • 13
  • 2

2 Answers2

1

You can't, you have to serve the file first.

Either you do it by creating a persistent reference string with a unique URL that temporarily references to the in-memory blob object that lives in the Blob URL Store by using URL.createObjectURL()

Or going to your local directory and serve it using http-serve then use the link as a path

localhost:8080/foo.txt
Achraf
  • 1,412
  • 10
  • 14
  • What does _"...,you have to serve the file first."_ mean? ... One can't, either before or after the file is selected. – Asons Jan 04 '19 at 22:20
0

If it's the path of a file, it can be done easily with node.js like so...

const path = require('path')
   path.dirname('whatSoEver')
Asons
  • 84,923
  • 12
  • 110
  • 165