Skip to content

How to upload files in FormData as Stream #1638

Answered by jimmywarting
ugonight asked this question in Q&A
Discussion options

You must be logged in to vote

for this end we need to be able to get Blob/Files backed up by the filesystem.
there is a feature request for this here: nodejs/node#37340 (give it a 👍)

anyhow... for now i think your best solution is to either

  1. read the hole file in to memory and construct a new File (like your uncommented line) (not recommended for large files)
  2. use something like fetch-blob to get Blob/Files that are actually backed up by the file system. (Undici support them as well if it acts like a duck and quack like a duck)
import { fileFromSync } from 'fetch-blob/from.js'

// will only stat the file for size & last modified date
const file = fileFromSync('test.mp4', 'video/mp4')
// this will not actually read any…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ugonight
Comment options

Answer selected by ugonight
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants