Multer failing to generate file during request process

My current setup involves a router and multer middleware, but I'm facing an issue where the file requested is not being created. As a result,

req.file

always remains undefined.

    const multer = require('multer');

let storage = multer.memoryStorage();

function fileFilter (req, file, cb) {
    if(file.mimetype === 'image/jpeg' || file.mimetype === 'image/png'){
        cb(null,true);
        return;
    }
    cb(new Error('wrong file type:not PNG or JPEG'),false);
}

const upload = multer({
    storage : storage,
    fileFilter : fileFilter
});

this.getServer().post('/vendor/profile/logo',upload.single('imageFile'),jwt,(req, res) => {
                this.addCompanyLogo(req).then(user => {
                    res.status(200).send(user);
                }).catch(err => {
                    console.log(err);
                    res.status(err.status).send(err.error);
                });
            });

I have also implemented bodyparser at the app level.

 server = express();
        server.use(bodyParser.json());
        server.use(bodyParser.urlencoded({ extended: true }));
        server.use(cors());

When making the request using postman :

https://i.stack.imgur.com/Me8Va.png

So far, none of my attempts have been successful. I've even tried removing bodyparser and reordering the middleware without any luck.

Answer №1

The problem ended up being linked to the file path on my local system which included special characters like ö that Postman doesn't support.

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

Tips for displaying a multi-line message through an npm script

Is there a way to display a multi-line message when running an npm script? My team has an alternative script called npm run publish:lib that should be used instead of npm publish. However, some team members tend to forget about this and end up using npm p ...

Customizing the CSS of the TinyMCE editor within a React application

Incorporating TinyMCE 5 into my React project has been an interesting challenge. I'm looking to personalize the editor by adjusting elements like borders and adding box shadows to the toolbar. Despite attempting to add CSS through the content_css prop ...

Please convert the code to async/await format and modify the output structure as specified

const getWorkoutPlan = async (plan) => { let workoutPlan = {}; for (let day in plan) { workoutPlan[day] = await Promise.all( Object.keys(plan[day]).map(async (muscle) => { const query = format("select * from %I where id in (%L) ...

Is there a way to ensure that browserify includes only the files I explicitly list and nothing else?

My current goal is to fine-tune my browserify build process. Essentially, I am looking to streamline the inclusion of specific server files in my bundle. I prefer to manually select the files I want included, especially since my project is quite extensive. ...

Issue with Chrome not triggering onMouseEnter event when an element blocking the cursor disappears in React

Important Note: This issue seems to be specific to Chrome Currently, React does not trigger the onMouseEnter event when a blocking element disappears. This behavior is different from standard JavaScript events and even delegated events. Below is a simpli ...

Stop the Sidebar from showing up on certain pages with Next.js

Currently, I am facing a small issue with my application. The problem lies in the sidebar that appears on my login.jsx page when I specifically do not want it there. However, I would like it to appear on all other pages except for this one. Is there a cond ...

Implementing Othello Minimax Algorithm in React.js Yields Unsuccessful Results

I need assistance with a recurring issue where the AI player consistently plays the first available move it encounters. My objective was to implement an AI using the Minimax Algorithm, but I'm facing challenges in achieving the desired functionality. ...

button to dim the image collection

On the top right corner of my image gallery, there's a button that, when clicked, creates an overlay darkening the image. I'm trying to figure out how to toggle this effect on and off with a click. Any suggestions on how I can achieve this? Here ...

Employing ng-repeat within a ui-scope

I'm having trouble getting my ui-view to update dynamically using ng-repeat. I'm not sure if what I want to do is even possible because when I add static objects to intro.html, they display properly. Thank you for any assistance, JS }).st ...

An HTTP OPTIONS request is sent prior to the actual request being made

As I work on developing the backend using node.js and mongoDB, focused primarily on API calls, I have noticed an interesting pattern. Every time I make a PATCH or DELETE API call, there is always an OPTIONS API call with the same URL right before it. The o ...

Create a user-friendly responsive tooltip in Javascript/jQuery with a convenient close

Looking to implement a tooltip feature that appears when a text box is focused on my responsive website, and disappears when it loses focus. Can anyone recommend the best JavaScript/jQuery library for this specific purpose? Here are my requirements: T ...

Determining the presence of a JWT token in local storage upon user navigation to a specific route in a Next.js application

In my current setup, I am utilizing Next.js(version 13) for the frontend and Express for the backend. It's important to note that my server is running on a different port from the client. The route for NEXTjs localhost is set to: localhost:3000/ "us ...

Terminate multiple axios requests using a common CancelToken

Within a single view, I have multiple react modules making API calls using axios. If the user navigates to another view, all ongoing API calls should be canceled. However, once they return to this view, these calls need to be initiated again (which are tri ...

Ways to obtain a tab and designate it as the default in angular when using angular material Tabs

I am facing an issue with accessing tabs within a nested component. The parent component contains the tab feature and to reach the tabs inside the child component, I am using the following code: document.querySelectorAll('.mat-tab-group'); The a ...

Is there a way to transform a callback into promises using async/await, and convert a prototype function into a standard

I need help converting a code callback function to promises. When attempting to convert the prototype to a normal function, I encounter an error that I can't fix on my own. I am eager to utilize the ES7 async-await feature to avoid callbacks. functio ...

Identify the significance within an array and employ the filter function to conceal the selected elements

I'm in the process of filtering a list of results. To do this, I have set up a ul list to display the results and checkboxes for selecting filter options. Each item in the ul list has associated data attributes. When a checkbox with value="4711" is c ...

Creating a structure for data in Ruby on Rails to facilitate AJAX calls to controller actions

I am in need of a button on my website that can send data to the create action of a controller named "pagetimes". The functionality seems to be partially working, but it is not sending all the specified data. This issue may be due to my inability to struct ...

Tips for resolving the Unexpected token - in JSON at position 0 issue

Trying to figure out how to successfully create a user in Postman using an HTTP post request. I utilized form-data to input the keys and values, but encountered an error message stating SyntaxError: Unexpected token - in JSON at position 0. Any suggestions ...

Can you provide a tutorial on creating a unique animation using jQuery and intervals to adjust background position?

I am attempting to create a simple animation by shifting the background position (frames) of the image which serves as the background for my div. Utilizing Jquery, I aim to animate this effect. The background image consists of 6 frames, with the first fr ...

Having trouble accessing functions in Typescript when importing JavaScript files, although able to access them in HTML

Recently, I started incorporating TypeScript and React into my company's existing JavaScript code base. It has been a bit of a rollercoaster ride, as I'm sure many can relate to. After conquering major obstacles such as setting up webpack correc ...