如何获取文件的绝对路径

时间:2019-01-04 22:12:07

标签: javascript

我正在尝试获取用作静态引用的绝对路径

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

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

但是我只得到文件名。

例如,如果我需要在本地打开图像,则需要提供网址

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

2 个答案:

答案 0 :(得分:1)

不能,您必须先提供文件。

任何一种都可以通过使用URL.createObjectURL()创建具有唯一URL的永久引用字符串来永久引用驻留在Blob URL存储区中的内存中Blob对象来实现, >

或者转到您的本地目录并使用http-serve进行投放,然后使用链接作为路径

localhost:8080/foo.txt

答案 1 :(得分:0)

如果它是文件的路径,则可以使用node.js轻松完成  像这样...

const path = require('path')
   path.dirname('whatSoEver')