Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import fs from 'fs';
- import path from 'path';
- export const uploadFile = async (stream, filename) => {
- const tempdir = path.resolve(__dirname, '../public/uploads/');
- const extension = filename.split('.').pop();
- const tempName = `${ Date.now() }.${ extension }`;
- const outStream = fs.createWriteStream(path.join(tempdir, tempName));
- await stream.pipe(outStream);
- console.log('uploading %s -> %s, %s', filename, outStream.path, tempName);
- return `uploads/${ tempName }`;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement