how to chunk video file with fs.createReadStream on H3 and how to hundle it in frontend

import fs from "fs"
import path from "path"


function getFileNameFromPath(path: string) {

let splitStr = path.split("/");
let filename = splitStr[splitStr.length - 1];
return filename
}


export default defineEventHandler(async (event) => {
const { slug } = getRouterParams(event)

const fileName = getFileNameFromPath(slug)

const file_name = path.join(process.cwd(), "/uploads", fileName)

const pathVideo = path.resolve(file_name)
const stat = fs.statSync(pathVideo)

const fileSize = stat.size



if (fs.existsSync(file_name)) {
const head = {
'Content-Length': fileSize.toString(),
'Content-Type': 'video/mp4',
};

appendResponseHeaders(event, head);
return fs.createReadStream(pathVideo)
}

})
import fs from "fs"
import path from "path"


function getFileNameFromPath(path: string) {

let splitStr = path.split("/");
let filename = splitStr[splitStr.length - 1];
return filename
}


export default defineEventHandler(async (event) => {
const { slug } = getRouterParams(event)

const fileName = getFileNameFromPath(slug)

const file_name = path.join(process.cwd(), "/uploads", fileName)

const pathVideo = path.resolve(file_name)
const stat = fs.statSync(pathVideo)

const fileSize = stat.size



if (fs.existsSync(file_name)) {
const head = {
'Content-Length': fileSize.toString(),
'Content-Type': 'video/mp4',
};

appendResponseHeaders(event, head);
return fs.createReadStream(pathVideo)
}

})
hallo there. i need your help to how to write chunk for video file . and how the frontend handled the chunk response, my goal is to delivery the video with small pieces. thanks for your help
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server