Does fetch in Xd support the .blob() or .arrayBuffer() methods on the response body?

Using

await fetch(url)

to get a png image from the web (which succeeds, as the resulting response has normal status (OK), content-length is 46653, etc.

Using .json() complains rightly that it’s not a json-formatted response, but .blob is undefined, and .arrayBuffer() just returns empty.

So I’m suspecting that Xd’s fetch isn’t a full implementation? Can you confirm?

This is a real problem if so.

blob is not supported currently. For fetching images, please consider using XHR for now. Here is an example! https://github.com/AdobeXD/plugin-samples/blob/master/how-to-make-network-requests/main.js

1 Like

Great, thanks!

Can you add those to the wish-list for fetch()?

blob support is coming soon! ref: https://trello.com/b/WFKmCVaz/xd-extensibility-roadmap

Great, thanks!

Also, what about ImageFill taking more than just a file ref or data: url? How about a binary blob as well, like what you’d get directly from fetching a url for a .png/.jpg/.gif?

Nice example, but I tested it, and seems like it’s not working…
I’m getting this error:
Plugin InvalidStateError: responseType should be the empty string or "text"

I figured out the way how it works :tada:

// Working example
const response = await fetch(url, {
  headers: new Headers({
    'x-requested-with': 'AdobeXD Desktop'
  })
});
const buffer = await response.arrayBuffer();

@kerrishotts or @peterflynn How close is blob support now?

2 Likes