I have the following video
URL: https://static.videezy.com/system/resources/previews/000/000/161/original/Volume2.mp4
and want to download it with Axios
chunk by chunk and write to the response (send to client)
Here, I do not know how to use Range Header
const express = require('express')
const app = express()
const Axios = require('axios')
app.get('/download', (req, res) => {
downloadFile(res)
})
async function downloadFile(res) {
const url = 'https://static.videezy.com/system/resources/previews/000/000/161/original/Volume2.mp4'
console.log('Connecting …')
const { data, headers } = await Axios({
url,
method: 'GET',
responseType: 'stream'
})
const totalLength = headers['content-length']
let offset = 0
res.set({
"Content-Disposition": 'attachment; filename="filename.mp4"',
"Content-Type": "application/octet-stream",
"Content-Length": totalLength,
// "Range": `bytes=${offset}` // my problem is here ....
});
data.on('data', (chunk) => {
res.write(chunk)
})
data.on('close', function () {
res.end('success')
})
data.on('error', function () {
res.send('something went wrong ....')
})
}
const PORT = process.env.PORT || 4000
app.listen(PORT, () => {
console.log(`Server is running on port: ${PORT}`)
})