S3 limiting file size based on fieldName on upload.fields
- Dominant language
- JavaScript
- Stars
- 12.1k
- Forks
- 1.1k
- Avg merge
- 8d 2h
- Merged PRs (30d)
- 21
Description
I want to be able to filter files based on different file extensions. One idea would be to pass a middleware after the upload which handles it. Like this:
```javascript
app.post("/upload", S3.upload.fields([{
name: 'video',
maxCount: 1,
}, {
name: 'subtitles',
maxCount: 1,
}]), validateUploadForms, validateUploadSizes, async function(req, res, next) {
console.log("Success");
});
function validateUploadSizes(req, res, next) {
if (req.files.video[0].size > 2000) {
return next();
} else {
res.json({
response: Strings.ERROR
});
return next(new Error);
}
}
```
But the problem here is that the file is already finished uploading so I will have to waste extra space and time on removing it.
Another idea would be to do something like this:
```javascript
app.post("/upload", S3.upload.single("video"), S3.upload.single("audio"), validateUploadForms, async function(req, res, next) {
console.log("Success");
});
```
And then use the `fieldSize`/`fileSize` property. But I am unsure on how it would work like. The problem here is that I can't use multiple `upload.single` middlewares.
What can I do? I am using S3/MulterS3
Contributor guide
Assessment
This issue has not been assessed yet.