Fetch image from API

后端 未结 1 1768
南旧
南旧 2020-12-30 23:08

Q1) In my reactjs application, I am trying to fetch an API from my backend Nodejs server. The API responds with an image file on request.

I can acce

相关标签:
1条回答
  • 2020-12-30 23:54

    The response from the server is a binary file, not JSON formatted text. You need to read the response stream as a Blob.

    var outside
    
    fetch(fetchURL + image)
      //                         vvvv
      .then(response => response.blob())
      .then(images => {
          // Then create a local URL for that image and print it 
          outside = URL.createObjectURL(images)
          console.log(outside)
      })
    
    0 讨论(0)
提交回复
热议问题