Fetch returning empty blob although Content-Length correct

#1

I am trying to retrieve a raw image through the fetch API, however, the result is empty even though the content headers show the request worked as expected.

While I understand that Expo provides the FileSystem.downloadAsync method for saving images, my endpoint (different from the example) requires a POST request meaning downloadAsync is not suitable.

When making the POST request, I get the same behaviour.

  • I have added the URL directly to an image element and it loads fine.
  • I have tried using text() and json() just to see if the result changes and in both instances the response was empty.
  • I have tried using an API Tester such as this: https://apitester.com/ and the result shows as I would expect

The following can be found in my snack

This is my request:

fetch('https://i.imgur.com/c9waLgY.jpg')
      .then(result => {
        console.log(result)
        return result.blob()
      })
      .then(result => {
        console.log('blob', result);
      })
      .catch(error => console.log(error));

Which returns the following headers:

content-type:"image/jpeg"
access-control-allow-methods:"GET, OPTIONS"
access-control-allow-origin:"*"
cache-control:"public, max-age=31536000"
x-cache-hits:"1, 1"
date:"Wed, 23 Jan 2019 21:10:36 GMT"
accept-ranges:"bytes"
etag:""bcb343578e3ea0d0d824f62e66d22bf0""
server:"cat factory 1.0"
age:"15302"
last-modified:"Wed, 23 Jan 2019 16:00:45 GMT"
x-timer:"S1548277836.140914,VS0,VE2"
content-length:"192289"
x-served-by:"cache-iad2133-IAD, cache-sea1051-SEA"
x-cache:"HIT, HIT"

And the following blob:

blobId:"a910e21b-80ba-44da-b6fa-20194b152538"
offset:0
size:0
type:""
lastModified:1548278321298

What am I doing wrong?

closed #2

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.