如何使用sendFIle()在Expressjs api get请求中发送多个图像

如何使用sendFIle()在Expressjs api get请求中发送多个图像,api,express,mean-stack,sendfile,Api,Express,Mean Stack,Sendfile,我正在寻找通过api从Expressjs服务器在一个GET请求中发送多个图像的方法 我想创建一个图像库的每个用户上传的图像在一个平均堆栈。当使用multer上传图像时,图像信息保存到mongodb,包括上传者的用户ID 在angularjs上,我希望用户能够访问他们之前上传的任何图像。目前我正在根据用户id发送一个GET请求文件。是否在一个json中发送多个文件。我目前正在使用Expressjs的res.sendFile,但还没有找到任何关于发送多个文件的信息 以下是我当前的get请求: ex

我正在寻找通过api从Expressjs服务器在一个GET请求中发送多个图像的方法

我想创建一个图像库的每个用户上传的图像在一个平均堆栈。当使用multer上传图像时,图像信息保存到mongodb,包括上传者的用户ID

在angularjs上,我希望用户能够访问他们之前上传的任何图像。目前我正在根据用户id发送一个GET请求文件。是否在一个json中发送多个文件。我目前正在使用Expressjs的
res.sendFile
,但还没有找到任何关于发送多个文件的信息

以下是我当前的get请求:

exports.getUpload = function(req, res) {
    Upload.find({createdby: req.params.Id}).exec(function(err, upload) {
        errorhandle.errorconsole(err, 'file found');
        console.log(upload[0]);
        var options = {
            root: '/usr/src/app/server/public/uploads/images'
        };
        var name = "" + upload[0].storedname +"";
        console.log(name);
        res.sendFile(name, options,function(err) {
            errorhandle.errorconsole(err, 'file sent');
        });
    });
};

您不能使用
res.sendFile
。事实上,我认为你根本做不到。也许是,但我不确定

您可以发送一个JSON响应,其中包含指向所有图像的链接:

exports.getUpload = async (req, res) => {
    const uploads = await Upload.find({ createdby: req.params.Id }).exec()
    const response = uploads.map(image => {name: `https://example.com/uploads/images/${image.storedname}`})
    res.json(response)
}
注意:省略了错误处理