I need to send post request to Another API, which will return result about 7 seconds.
If I try to send post one by one, it's working great. But as soon as I loop it or send multiple request, it returns errors.
The errors are sometimes Error: socket hang up
or status code: 504
I've tried
multiple
then().then().th
async/await
inside for loopaync/await
line by line like thisconst toonifyNewFileName = `./uploads/Toonified-toonify-${baseFileName}` const toonifyRes = await axios.post(toonifyUrl, formData, {headers: headers}) var {data:{num_faces, b64_encoded_output}} = toonifyRes; var base64Buffer = Buffer.from(b64_encoded_output, "base64"); writeFile(toonifyNewFileName, base64Buffer, err => console.log("DONE 1")); const comicNewFileName = `./uploads/Toonified-comic-${baseFileName}` const comicRes = await axios.post(comicUrl, formData, {headers: headers}) var {data:{num_faces, b64_encoded_output: newB64}} = comicRes; var base64Buffer2 = Buffer.from(newB64, "base64"); writeFile(comicNewFileName, base64Buffer2, err => console.log("DONE 2"));
It doesn't matter with writeFile()
, I've deleted, it didn't work.
My guess is that since the first request takes about 7 to 8 seconds, that's why it causes error for next request?
to sum up
I need to post multiple requests that each of them takes about 7 to 8 seconds.
But it returns socket hang up
error or status code: 504 GATEWAY TIME OUT
what should I do?