express获取本地⽂件夹下的图⽚和⽂件
在routes⽂件夹下创建了getImages.js⽂件,getImages.js中的代码:
高速路免费时间2022春节var express = require('express');
var router = express.Router();
var fs = require('fs');
陈妍希男友var image = require("imageinfo");
<('/', function(req, res, next) {
function readFileList(path, filesList) {
var files = fs.readdirSync(path);
files.forEach(function (itm, index) {
张雨绮八卦var stat = fs.statSync(path + itm);
if (stat.isDirectory()) {
//递归读取⽂件
readFileList(path + itm + "/", filesList)
} else {
var obj = {};//定义⼀个对象存放⽂件的路径和名字
obj.path = path;//路径
obj.filename = itm//名字
filesList.push(obj);
}
})
}
var getFiles = {
getFileList: function (path) {
var filesList = [];
readFileList(path, filesList);
return filesList;
员工培训方案},
getImageFiles: function (path) {
var imageList = [];
var ms = adFileSync(item.path + item.filename));
ms.mimeType && (imageList.push(item.path +item.filename))
});
金字塔里的秘密res.send(imageList);
国庆高速免费时间2022最新通知return imageList;
}
};
//FileList("./public/images/");
});
运⾏后,打开浏览器
图⽚地址成功返回
发布评论