Fetch data-uri in Autotask

Pretty straightforward issue - I'm using fetch in an autotask to fetch metadata for an ERC721.

Some folks are starting to return data-uri stringss of base-64 encoded json at tokenURI, such as


In most browsers and node, this is a fine things to fetch and conveniently works the same as an https url.

In an autotask, I get the following error: Only HTTP(S) protocols are supported

2021-10-11T00:45:03.433Z	ERROR	Invoke Error 	{"errorType":"TypeError","errorMessage":"Only HTTP(S) protocols are supported","stack":["TypeError: Only HTTP(S) protocols are supported","    at getNodeRequestOptions (/opt/nodejs/node_modules/node-fetch/lib/index.js:1303:9)","    at /opt/nodejs/node_modules/node-fetch/lib/index.js:1404:19","    at new Promise (<anonymous>)","    at fetch (/opt/nodejs/node_modules/node-fetch/lib/index.js:1401:9)","    at /var/task/index.js:94:42","    at step (/var/task/index.js:66:23)","    at Object.next (/var/task/index.js:47:53)","    at fulfilled (/var/task/index.js:37:58)","    at processTicksAndRejections (internal/process/task_queues.js:97:5)"]}
END RequestId: b36078b1-cd07-48cd-ba1c-9c4c5dcc8340

I'm able to work around it like this:

  const json = Buffer.from(tokenURI.substring(29), 'base64').toString();
  const result = JSON.parse(json);

But it would be nice not to have to worry about the conditional.

Any chance data-uris could be fetched in an autotask? Or am I being really naive about the security implications?

Hey @sbauch! This is not a security limitation of Autotasks, but a difference in the node-fetch version. Autotasks include v2 of the library, which doesn't support data-uris. And since v3 doesn't support require for importing the module, (which several users rely on) I'm not sure it's a good idea to upgrade the library in the set of Autotask dependencies. But you can bundle node-fetch v3 on your own Autotask if you want to use it, and you should be able to transparently handle data-uris!

ah wonderful. thanks for the explanation!

1 Like