#download url params based image with axios
1 messages · Page 1 of 1 (latest)
yeah that URL works fine for me. what i was asking is when you call downloadFile are you 100% sure you are using that exact URL? sounds like the answer is "yes" though
i tried browser and curl, both work. i was thinking it might be due to headers, but that host seems very forgiving
yeah accept doesn't seem to matter, they return an image even for text/plain (which is wrong, but whatever)
could you try this simpler thing and let me know what gets logged?
async function debug() {
await axios.get('https://s.namemc.com/2d/skin/face.png?id=02a3b3079e99fd6f&scale=16', {
responseType: 'stream',
validateStatus: () => true
}).then(console.info).catch(console.error)
}
weird, when i make a request using those exact headers, etc i get a 200 response with the image:
curl "https://s.namemc.com/2d/skin/face.png?id=02a3b3079e99fd6f&scale=16" \
-H"Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8'" \
-H"User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:107.0) Gecko/20100101 Firefox/107.0" \
-H"Accept-Language: en-US,en;q=0.5" \
-H"Accept-Encoding: gzip, deflate, br" \
-H"Connection: keep-alive" \
-H"Upgrade-Insecure-Requests: 1" \
-H"Sec-Fetch-Dest: document" \
-H"Sec-Fetch-Mode: navigate" \
-H"Sec-Fetch-Site: cross-site" \
--output test.png \
-vvv
is it possible your host is blocked? maybe you spammed too many requests?
i've got to run to a meeting in a minute, so don't have time to try the exact axios setup you're using, but off the top of my head i don't know what would be special about it
sorry if that was confusing, but i copied those headers out of your logs. it's what axios was already using
don't bother. i just ran curl on the command line. was just trying to independently test
oh alright 😄
i'd probably need to set up a node project with axios to be able to reproduce the problem you're seeing, but i need to wrap up a work thing before i can do that
in the meantime my only other suggestions are deeper debugging (look at the actual network traffic to see if anything jumps out), or just blindly trying a different library (or just native fetch if your runtime has it)
axios isn't magic though, something about the exact HTTP request it's sending is causing s.namemc.com to respond with a 404
i just tried this and it works for me ¯_(ツ)_/¯
as in i get a 200 OK
you can see exactly what i did here: https://github.com/mkantor/test-axios-namemc
do you have access to a host on a different network you could try from (like a server in the cloud or a VPN you could connect to or something?)
seems like we've eliminated everything except your location/IP being relevant. they could be fingerprinting the exact request details that axios sends, combining that with your IP, etc, and blocking that specific combination of stuff? i'm just making wild guesses here though
it's a good question. axios is fairly high-level, so maybe it's adding its own headers or something? again just wild guesses here. if you could inspect the raw network traffic (using wireshark or similar) you could see exactly what is being sent
hmm, are they sending you back a redirect that axios is silently following?
i know this is beside the point, but these days i'd just use the native fetch function unless you have a specific reason to avoid it
it's built in in modern node versions, comes standard in browser runtimes, etc
i'm not totally sure about the stream APIs for node, but that at least looks approximately correct
maybe pipeTo or pipeThrough based on https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream