menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Streamlini...
source image

Dev

2d

read

55

img
dot

Image Credit: Dev

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

  • Integrating the Sightengine image moderation API into a Node.js application led to encountering and solving various challenges.
  • Initially attempted to use native fetch and form-data in Node.js, which resulted in errors like ConnectTimeoutError and DNS ENOTFOUND.
  • Resolved DNS issues by bypassing the systemd-resolved resolver and pointing to public DNS.
  • Encountered limitations with Blob vs. streams while trying to stick with pure native APIs.
  • Opted for the final solution using form-data and node-fetch, providing a reliable approach in Node.js for file uploads with multipart requests.
  • The final code setup mirrors curl -F, streams the file efficiently, and ensures valid multipart requests.
  • In conclusion, by fixing DNS resolver, understanding FormData limitations in Undici, and resorting to form-data + node-fetch, a robust streaming multipart setup akin to curl -F can be achieved in Node.js.

Read Full Article

like

3 Likes

For uninterrupted reading, download the app