jimmywarting / FormData

HTML5 `FormData` polyfill for Browsers and nodejs
MIT License
360 stars 102 forks source link

Example in the readme is confusing #141

Closed GrosSacASac closed 2 years ago

GrosSacASac commented 2 years ago

The following line:

fd.append('file-upload', new File(['abc'], 'hello-world.txt'))

I thought I would stream the file hello-world.txt

jimmywarting commented 2 years ago

so the way you would actually stream a file is that you would somehow get a File class from the filesystem that would stream the file for you.

the file class itself has a File.prototype.stream() method that we will call to read the file


so you wouldn't actually stream the file into a formdata, we read the data for you...

jimmywarting commented 2 years ago

NodeJS is plaining on implementing a method to get Blob/Files from the filesystem somehow but in the meantime you would need something like: https://github.com/node-fetch/fetch-blob#blob-part-backed-up-by-filesystem

jimmywarting commented 2 years ago

The File class is also constructible, so you can create files in memory

GrosSacASac commented 2 years ago

Thanks for the details