简体   繁体   中英

Get filename from url

I am using file picker. File picker gives me a url like this after saving the file https://www.filepicker.io/api/file/YVlnXammQium3ukD3Zf4

But how do I know what the file name is? When I enter this URL in my browser I get the download tab and the tab shows me the filename . How can I get the file name using javascript ?

Is there another way to get the file name? I am using Rails as a backend and Backbone as the front end.

You can get the filename via metadata :

https://www.filepicker.io/api/file/hFHUCB3iTxyMzseuWOgG/metadata?filename=true

In Javascript this would look like:

var blob = { url: 'https://www.filepicker.io/api/file/hFHUCB3iTxyMzseuWOgG' };

console.log("Loading metadata...");
filepicker.stat(
  blob,
  {
    filename: true
  },
  function(metadata){
    console.log(JSON.stringify(metadata));
  }
);

All of this is in the documentation , so take a look there for more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM