1.0.2 • Published 5 years ago
@vagnercardoso/multer-mux-storage v1.0.2
multer-mux-storage
Uploading video to MUX using Multer with Express
Installation
npm install @vagnercardoso/multer-mux-storage
Usage
Using express with typescript:
import express from 'express';
import { MuxStorage } from '@vagnercardoso/multer-mux-storage';
import multer from 'multer';
const app = express();
const multerMuxStorage = multer({
storage: new MuxStorage({
tokenId: process.env.MUX_TOKEN_ID,
tokenSecret: process.env.MUX_TOKEN_SECRET,
allowedMimeTypes: ['video/mp4'],
}),
});
app.post('/upload', multerMuxStorage.single('archive'), (request, response) => {
return response.json(request.file);
});
app.listen(3000, () => {
console.log(`app running on port 3000`);
});MuxStorage constructor
Possible settings to pass to the class's constructor
{
tokenId: string;
tokenSecret: string;
allowedMimeTypes: string[];
getUploadOptions?: (
request: Request,
file: Express.Multer.File,
) => Promise<UploadOptions>;
}Required options
tokenIdtoken provided by mux.comtokenSecretsecret key provided by mux.comallowedMimeTypesreceives an array of possible mimetypes to accept the upload
Optional options
getUploadOptionsasync function that receives the request is the file per parameter to return the request parameters to create the upload in mux.
Data returned along with the multer in the interface Express.Multer.File
muxUploadIdid of the upload done on mux
To retrieve the id in your route, you must use request.file.muxUploadId
The id is for you to be able to retrieve the created assets and have all the information of your uploaded video.