cosmicjs / cosmic-sdk-js

The official JavaScript SDK for Cosmic. Use it to power content server-side, in the browser, and in native apps.
https://www.npmjs.com/package/@cosmicjs/sdk
MIT License
12 stars 1 forks source link

Use a spec-compliant FormData polyfill or drop node <18 #35

Open KaelWD opened 1 week ago

KaelWD commented 1 week ago

form-data does not support File objects https://github.com/form-data/form-data/issues/124, which means media uploads need to do

media: {
  originalname: file.name,
  buffer: Buffer.from(await file.arrayBuffer(), 'binary'),
},

instead of just

media: file
tonyspiro commented 1 week ago

Thank you @KaelWD. This is noted in the docs. Do you have a recommended implementation for this? Feel free to make a PR.

KaelWD commented 1 week ago

Currently I'm just using patch-package to remove the form-data import, node has had FormData built in since v18.