Trouble getting a file from local node

Thought I had this fixed but it stopped working again :frowning:

const stream=async(url,data,mimeType,method="POST")=>{
    return new Promise((resolve,reject)=>{
        let oReq = new XMLHttpRequest();
        oReq.open(method, url, true);
        oReq.responseType = "arraybuffer";
        oReq.setRequestHeader("Content-Type", "application/json;charset=UTF-8");

        oReq.onload = function() {
            let arrayBuffer = oReq.response;
            resolve(new Blob([arrayBuffer], {type: mimeType}));
        }
        oReq.onerror = function (e) {
            reject(e);
        }

        oReq.send(JSON.stringify(data));
    });
}

worked a few times returning a Blob when I call

let blob=await stream("http://ipfs.localhost:8080/ipfs/QmdtLCqzYNJdhJ545PxE247o6AxDmrx3YT9L5XXyddPR1M",undefined,"image/png","GET");

but now it just throws an error. Any suggestions? The file requested is pinned and shows correctly with the URL in the browser.

Without knowing what error it’s kinda hard to guess but maybe CORS?

not CORS but in copying headers to respond to you I noticed i missed the undefined in my code so it was POST ing the request which is not accepted. Thanks for the indirect help.

1 Like