I'm still quite new to Promises and would like some clarification.
For some context, I'm trying to get a file from an URL. The file is stored using IPFS and when there's a timeout I would like to try and call axios.get()
again.
My current problem is, that it looks like the file is being downloaded but the function rarely returns anything, it looks like the download is super slow, however if I open the link directly I get the file instantly, making me think there's something wrong with my promises, even though no then()
nor catch()
is ran. My current code is as follows:
const getIPFSMedia = (url) => {
return axios.get(url, { responseType: 'blob' }).then((response) => {
return URL.createObjectURL(response.data);
}).catch((e) => {
if (e.message === GET_IPFS_TIMED_OUT) {
return getIPFSMedia(url);
} else {
console.log(e.message);
}
});
}
const fetchData = async() => {
const image = await getIPFSMedia(url); // Slow or rarely returns, but when it does it has my file in it
console.log(image)
}