Home > Enterprise >  How can I get jpg files path for javascprit
How can I get jpg files path for javascprit

Time:10-24

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

CodePudding user response:

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);
    });
});
  • Related