octet-stream / form-data

Spec-compliant FormData implementation for Node.js
https://www.npmjs.com/package/formdata-node
MIT License
142 stars 17 forks source link

Cannot post images for lacking getBoundary function #66

Closed NoodleHJ closed 1 year ago

NoodleHJ commented 1 year ago

Hi, Im using trying to post image with node-fetch. But it does not has getBoundary function, so node-fetch will consider it as normal text. Does anyone know how to tackle this issue?

FYI: node-fetch @2.6.1 & formdata-node@^5.0.1

jimmywarting commented 1 year ago

Node-fetch v3 supports this spec compatible FormData implementation.

In v3 we decided to remove support for form-data package that relied on getBoundary and other non spec related stuff

Updating to v3 could be one option. Then it will also ship with a built in FormData that is also exported without any additional dependencies.

Alternative is to just update NodeJS to v18+ that now also have FormData and fetch built right in. So no dependencies are no longer needed

To post images from files use the new fs.openAsBlob

octet-stream commented 1 year ago

FYI: node-fetch@2.6.1 & formdata-node@^5.0.1

If you are using formdata-node v5, you probably can upgrade node-fetch to v3. As previous commenter said - it has support for spec-compliant form-data implementations. The getBoundary method is specific to form-data package and it's not standard, so I won't support it.

If for some reason you need node-fetch v2, try form-data-encoder - it will perform multipart/form-data encoding for you.

octet-stream commented 1 year ago

I'm closing this issue assuming your question is addressed.