I'm want to upload big file to my localhost server. And because the file size will be big ( 500MB maybe ), so I need to send the data chunk by chunk from client. Then my Nodejs server will keep appending the data to a temp file. Finally, I will change the file format and save it.
The problem is, I don't know how to send & read data properly. This is how I'm doing now, in my server I keep getting {} object.
Client Side:
// Prepare & Start Upload
const reader = new FileReader();
reader.addEventListener("load", async () => {
await fetch('/api/v1/file/upload/', {
method: 'POST',
body: reader.result
});
})
reader.readAsArrayBuffer( file.slice(0) ); // try to read whole file(small) first
My app setup:
/* Register Middlewares */
app.use(express.json())
app.use(express.urlencoded({extended:true}))
app.use('/api/v1/file/upload', fileUploadRouter)
app.use(express.static('./views'))
app.use(appError)
/* App Start */
const PORT = process.env.PORT || 3000
app.listen(PORT, () => console.log('Listening to: localhost:'+PORT))
My route
fileUploadRouter.post('/', async ( req, res, next ) => {
var buffer = req.body
console.log(buffer)
})
Thank for your help!