JCMais / node-libcurl

libcurl bindings for Node.js
https://npmjs.org/package/node-libcurl
MIT License
666 stars 118 forks source link

Send binary data with HTTPPOST option #407

Closed juanch120 closed 8 months ago

juanch120 commented 9 months ago

I've tried for hours and hours to send a data-form POST method with binary data like this:

const formData: [{ name: 'file', content: *BINARY DATA* }]
curl.setOpt('HTTPPOST', formData)

but node-libcurl HTTPPOST 'content' field only accepts strings. Is this doable in any way? I'd like to be able to replicate this:

const formData = new FormData()
formData.append('file', new Blob([rawDataBuffer]), 'title')
const response = await fetch(url, { body: formData, method: 'POST' })
JCMais commented 8 months ago

The only way to do this right now is by writing the contents to a file or using the READFUNCTION option to build the parsing directly.

There is an open ticket to support the mime apis here: https://github.com/JCMais/node-libcurl/issues/112

which could help this use case, but I cannot say when I will be able to work on that.