What could be the reason for multer functioning properly with PNG and JPG files, but encountering issues with WebP files in my setup using Tsed, Express

I previously had my endpoint set up to handle png and jpg files successfully. However, I wanted to restrict it to only allow webp files. So, I updated the file filter callback accordingly. Unfortunately, now Multer does not save any files other than png or jpg without giving an error. It returns an object indicating successful saving but nothing actually gets saved on the disk.

What could be causing this issue?

Here is the configuration object I am using (specific to the tsed framework):

const storage = multer.diskStorage({
  destination: function (req: any, file: any, cb: any) {
    cb(null, './uploads')
  },
  filename: function (req: any, file: any, cb: any) {
      let extArray = file.mimetype.split("/");
      let extension = extArray[extArray.length - 1];
      cb(null, file.fieldname + '-' + uuidv4() + '.' +extension)
  }
})

  multer: {
    storage: storage,
    dest: `${process.cwd()}/uploads`,
    limits: {
      fileSize: 7340032,
    },
    fileFilter: (_req: any, file: any, cb: any) => {
        // Previous condition checking mimetype was removed for testing purposes with different mimetypes
        return cb(null, true);
    }
  }

My endpoint implementation:



  @Post("/photo")
  @Authorize("jwt") @Security("jwt")
  @Returns(200) 
  @Returns(401) 
  @Returns(404)
  private async simpleUpload(
    @MultipartFile("file") 
    file: PlatformMulterFile) {
    if (!file) {
      throw new NotFound('file not found');
    }
    console.log(file);
    return{filename : file.filename}
  }

Despite always receiving a 200 response, the console log output shows no file being saved on the disk when attempting to upload pdf or svg files.

Answer №1

The server configuration is perfectly fine. It only slipped my mind that there was a bash script set up to remove any files in the upload folder that were not png or jpg format.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The integration of Pure Bootstrap v4 with ReactJs is experiencing difficulties

I was eager to incorporate pure Bootstrap v4 into my React.js application. Initially, I set up my app using create-react-app and added Bootstrap assets to the index.html file in the public folder. Initially, everything worked fine. However, when I introdu ...

Utilizing the output from a console.log in a webpage

Although the function I created is functioning properly and successfully outputs the value to my terminal onSubmit, I am facing difficulty in understanding why this code isn't updating my html. router.post('/index', function(req, res, next) ...

Is it possible to have the node server and client operating on separate ports?

Here is the code that runs from a single call in my package.json: const express = require('express'); const app = express(); const port = 3000; //raspberryPI //const dotenv = require('dotenv'); const { ChatClient } = require("dank ...

Creating dynamic pages using user input in Node and Express

Currently, I am facing a challenge in rendering text using node/express. Within my project setup, there is an HTML file containing a form. The file named search.ejs looks like this: $(document).ready(function(){ var userInput; $("#submit-button-i ...

Unable to retrieve the userID from the express session

Trying to capture the user ID from the current session in order to create a delete profile function using express with express-sessions, mongoose, and passport. The code I'm using for deleting a user is functional. When manually inputting IDs from Mo ...

There was an error encountered while using the findOneAndRemove() method: TypeError - it was unable to read the property '_id' of an

I encountered an error 'TypeError: Cannot read property '_id' of undefined' when using the findOneAndRemove() function with the required parameters in MongoDB, even though my database has the attribute '_id'. Interestingly, w ...

Retrieve the route.js directory using Node.js

My server.js file is located in the directory: /dir1. To start the server, I use the command node server.js. In the directory /dir1/app/, I have my file named routes.js. I am trying to find out the directory path of the server.js file. However, I am unc ...

Retrieve req.session when the request object is unavailable (e.g. during a socket connection)

In order to detect when a user is connected using socket.io, I need to access the req.session.user._id within the function. Here is an example of how I would like to achieve this: io.on('connection', function(socket){ console.log('a user c ...

Using socket.io and express for real-time communication with WebSockets

I'm currently working on implementing socket.io with express and I utilized the express generator. However, I am facing an issue where I cannot see any logs in the console. Prior to writing this, I followed the highly upvoted solution provided by G ...

Leverage npm speaker as output for your GridFS download stream in your NodeJS application

Currently in the process of developing a music streaming platform using the MEAN stack. Progress has been made in coding that allows for mp3 file uploads to the MongoDB database through GridFS. The ability to download these files to the website's root ...

What are the steps to modify the authorization header of an HTTP GET request sent from a hyperlink <a href> element?

I have a unique Angular application that securely saves JWT tokens in localstorage for authentication purposes. Now, I am eager to explore how to extract this JWT token and embed it into an HTTP GET request that opens up as a fresh web page instead of disp ...

When I send data using axios, I receive the response in the config object instead of the data

Currently, my web app is being developed using NextJS NodeJS and Express. I have set up two servers running on localhost: one on port 3000 for Next and the other on port 9000 for Express. In the app, there is a form with two input fields where users can e ...

Troubleshooting ng-repeat issues within the MEAN stack framework

I've recently started working with the MEAN stack and was attempting to create a basic contact app, but I'm encountering issues with ng-repeat in my index.html file. Below is my code, following the default file structure provided by Express: ind ...

Retrieve the latest inserted ID in a Node.js application and use it as a parameter in a subsequent query

I am currently working with an SQL database that consists of two tables, namely club and players. These tables are connected through a one-to-many relationship. Although the query in my node.js code is functioning properly, I am facing an issue retrieving ...

Now that connect no longer utilizes the parseCookie method, what is the alternative method for accessing session data in express?

There are numerous examples in node.js and express showcasing how to access session data. Exploring Node.js and Socket.io Express and Socket.io Integration Understanding Socket.io and Session Management Upon visiting the third link, which leads to Stac ...

What is the best way to use the $push operation to add an object to an array within a mongoDB database using Node.js

I am trying to find a way to push an object into an array inside my MongoDB database. When using the $push method with submits[postDate], I am encountering an error with the syntax highlighting the first "[". Any suggestions on how to resolve this issue? ...

What is the process for uploading an image using Nodejs and Multer?

I am currently in the process of developing an application that involves uploading a file, such as an image, and then posting it on the platform. Here is what I have accomplished so far: const express = require('express'); const multer = requir ...

Exploring how to utilize optional URL parameters within Express.js

When using Express.js version 4.14, I implemented the following route: app.get('/show/:name/:surname?/:address?/:id/:phone?', function(req, res) { res.json({ name: req.params.name, surname: req.params.surname, address ...

How to enhance Node using Express for WebSocket pinging?

Currently, my project involves a game where players scan a QR code displayed on a TV screen. This action then initiates the controller on their smartphones and transfers player actions using websockets. In essence, it's simply transferring the value o ...

Is there a reason why Express is defaulting to error handling with a 404 response for all routes, including ones

I have created a fresh Express app using the express generator. In order to handle errors, I included a console.log in the error handler: // error handler app.use(function(err, req, res, next) { // set locals, only providing error in developm ...