DEV Community

Cover image for Streamlining Image Moderation API Uploads in Node.js: From Native Fetch to Form‑Data and DNS Fixes ⚙

Streamlining Image Moderation API Uploads in Node.js: From Native Fetch to Form‑Data and DNS Fixes ⚙

Ali nazari on June 14, 2025

In this post, we’ll walk through our journey integrating the Sightengine image moderation API into a Node.js application. Along the way, we encount...
Collapse
 
deividas_strole profile image
Deividas Strole

Great breakdown! Switching from native fetch to form-data in Node.js can really smooth out multipart uploads, especially when dealing with image moderation APIs. And that sneaky DNS resolution issue? Classic Node headache — glad you tackled it head-on. These kinds of insights save devs a ton of debugging time!

Collapse
 
silentwatcher_95 profile image
Ali nazari

Thanks! 🙌 Yeah, switching to form-data made a huge difference

Collapse
 
abrar_ahmed profile image
Abrar ahmed

Great insights! I’ve faced similar issues with Undici’s FormData while managing file streams — it’s really frustrating when it fails without any notice during an API upload.
If you’re debugging this: make sure your multipart payload is actually streaming, and don’t underestimate the quirks of DNS resolvers on Linux (I’ve been caught out by 127.0.0.53 more times than I can count).
A good fallback is using node-fetch with form-data. I’m curious if you’ve tried axios too? It’s great with streams, but it does come with a bit of overhead.

Collapse
 
silentwatcher_95 profile image
Ali nazari

I’ve mostly stuck with node-fetch + form-data as a reliable combo, but haven’t seriously tried axios for stream uploads yet.

Collapse
 
arshtechpro profile image
ArshTechPro

The DNS resolution issue via systemd-resolved was especially tricky—thanks for highlighting that fix. Also appreciate the clarity on Undici's Blob vs. stream limitations; it's not well-documented and can waste hours. The final solution with form-data and node-fetch is battle-tested and solid.

Collapse
 
silentwatcher_95 profile image
Ali nazari

Glad the fix helped!

Collapse
 
nevodavid profile image
Nevo David

pretty cool seeing someone stick it out til stuff finally works - you think it’s patience or just stubbornness that actually makes you push through all the tech headaches?

Collapse
 
silentwatcher_95 profile image
Ali nazari

Honestly, probably a mix of both

Collapse
 
dotallio profile image
Dotallio

Super helpful breakdown - I’ve run into almost the exact same fetch vs. form-data headaches.
Did you see any signs that native APIs might eventually make this less painful?

Collapse
 
silentwatcher_95 profile image
Ali nazari

Appreciate it! Yeah, you're definitely not alone—handling fetch and form-data in Node can feel way rougher than it should be. As for native APIs, there's some movement: newer Node versions are gradually aligning more with web standards (like the experimental FormData and Blob in undici), but there’s still a lot of edge-case pain, especially with streaming.

Collapse
 
smhkneonix profile image
Kneonix

what a great approach