Closed GrosSacASac closed 2 years ago
Solution was to use node-fetch 3.1.0
tip, if you want to have same FormData dependency as node-fetch without additional imports in packages json then you could do:
import {Response} from 'node-fetch'
const FormData = (await new Response(new URLSearchParams).formData()).constructor
const Blob = (await new Response().blob()).constructor
// Hack to get the same file class:
const fd = new FormData(); fd.set('x', new Blob())
const File = fd.get('x').constructor
uploadFile.js
patchNode/FormData.js
I make a simple POST request with a FormData When I use formdata-polyfill library with fetch and use additional headers, the most important header with Content-Type and boundary gets lost. (replaced by text/plain)
When I use form-data library I can access getHeaders
{ 'content-type': 'multipart/form-data; boundary=--------------------------971495223106834682165883' }
and with ...append it to my headers before making the fetch.How to send a form with additional headers in node.js with fetch