Closed iVodkabulary closed 10 months ago
Hello. First of all, which version of formdata-node
and and axios
you use?
im using "formdata-node": "6.0.3" "axios": "1.6.2"
I was asking formdata-node
version and not form-data
:)
I was asking
formdata-node
version and notform-data
:)
sorry i already edited above
I have tried with
{
"axios": "1.6.5",
"formdata-node": "6.0.3",
}
And everything works as expected.
Here's the code:
import {fileFromPath} from "formdata-node/file-from-path"
import {FormData} from "formdata-node"
import axios from "axios"
const form = new FormData()
form.set("file", await fileFromPath("path/to/some/file"))
console.log(await axios.post("https://httpbin.org/post", form))
Somehow after getting home and running code on my Windows laptop it returned another error: ReadableStream is not defined... I'm using node 16.20.0
This is because Node.js exposed ReadableStream class staring Node.js v18. But it's available since 16.5 under node:stream/web
module.
Also, formdata-node
requires Node.js 18, because Node.js 16 reached EOL on 11th of Sept, 2023.
oh ok i understand now. I will see what can I do. Thank you for your support.
Please keep this issue open until it's resolved. I will close it eventually, if you don't respond in a few days or weeks assuming it was resolved.
If that's possible, try another http client, like got
or undici
and try at least Node.js 18 or later. They even has builtin fetch and FormData, also you can replace fileFromPath
with fs.openAsBlob
. Yes, on latest Node.js version you don't need a ponyfill in order to use fetch API (tho, they do seem to support 3rd party FormData implementations).
yes I'm planning to upgrade my server to Ubuntu 20.04 so it can support nodejs higher version then i can use the implemented formData. So i will mark this issue as resolved cause i won't try using the formdata-node anymore. Thank you very much.
Can you please help?
Source code is something like this: