Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if request file is type zip

Im using the following code to get single files/ zip from postman.

In the request im asking for a file original name and can check if the file originalname contain .zip or not ,is there a better way to check if it single file or zip ?

update function (req, res) {
        if (req.file) {

1 Answers

I've had to do this in the past and the cleanest way I've found is to check the mimetype of the file from the request:

if(req.file.mimetype === 'application/zip')

Bonus being there's no need for external depedencies.