How to get the image extension from a remote image url that doesn't contain image extension in the url

前端 未结 1 1219
隐瞒了意图╮
隐瞒了意图╮ 2020-12-21 08:52

I\'m trying to use the Image API to get the image data/extension for image urls.

I can easily use regex to the file extension from names like {domain}.com/path-to-im

相关标签:
1条回答
  • 2020-12-21 09:14

    You can use fetch(), Response.blob(), FileReader.prototype.readAsDataURL()

    fetch("http://placekitten.com/g/1000/1000")
    .then(response => response.blob())
    .then(blob => {
      console.log(blob.type);
      let reader = new FileReader();
      reader.onload = () => {
        console.log(reader.result)
      }
      reader.readAsDataURL(blob) 
    })
    
    0 讨论(0)
提交回复
热议问题