Search code examples
angularexpressmulter

How to upload and view an image file from server


I am using multer to upload files. It gets uploaded to "Public" folder which is present outside "dist" folder.

I want to display the image after uploading using the uploaded path as src.

I know this question might be silly. But I am not able to think of anything.

Need help guys !!


Solution

  • You have to add the path in your app.js file.

    like this:

    app.use('/public', express.static(path.join(__dirname, '/Public')));
    

    OR

    app.use('/public', express.static(process.cwd() + '/Public'));
    

    Then you will be able to access it any where in angular like this:

    <img src="/public/image_name.jpg" />