menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Streamlini...
source image

Medium

2d

read

295

img
dot

Image Credit: Medium

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

  • The article discusses the challenges faced while trying to mirror a curl -F snippet in pure Node.js for streamlining image moderation API uploads.
  • Using undici and the form-data package initially led to ConnectTimeoutError and DNS ENOTFOUND issues, despite curl working fine.
  • A workaround involved bypassing the resolver systemd-resolved and pointing to public DNS to resolve the API host.
  • After restarting systemd-resolved, both nslookup and the Node.js code managed to resolve the API host.
  • Attempts were made to rely on pure native APIs, but FormData.append in Undici only accepted string, Buffer, or Blob contents, resulting in errors.
  • The most reliable approach chosen in Node.js involved using a specific method to mirror curl -F, stream the file to avoid a memory hit, and generate valid multipart requests.

Read Full Article

like

17 Likes

For uninterrupted reading, download the app