Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I get jpg files path for javascprit

I’m adding jpgs to the upload folder, how can I get the path of these jpgs

my code

 const dbattachement = [];
readdir(filePath, 'utf8', (err, files) => {    
  if (err) {
    return console.log('Unable to scan directory: ' + err);
} 

files.forEach(function (file) {
    console.log(file); 

});
});

only jpg name returning me
How can I get the path of the jpg

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Just Justinas mentioned, when you upload a new picture to your folder, you already knew the path of your folder.

const fileFolder = './Images/'; // Your upload folder path
const fs = require('fs');

const dbattachement = [];

fs.readdir(fileFolder, (err, files) => {
    if (err) {
        return console.log('Unable to scan directory: ' + err);
    }

    files.forEach((file) => {
        console.log(__dirname + '/Images/' + file);
        dbattachement.push(__dirname + '/Images/' + file);
    });
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading