cosette/server/api/image/[uuid].js

13 lines
371 B
JavaScript
Raw Permalink Normal View History

2022-08-26 16:31:33 +02:00
import fs from 'node:fs'
import path from 'path'
import { sendStream } from 'h3'
export default defineEventHandler(event => {
const uuid = event.context.params.uuid
const filePath = path.resolve('./server/public/images/', uuid)
if (!fs.existsSync(filePath)) {
throw new Error('File not found!')
}
return sendStream(event, fs.createReadStream(filePath))
})