如何在网站上看到所有上传的图片?

问题描述 投票:0回答:0

所有上传的图片都显示在“上传”文件夹中。 但是我怎样才能在网站上找到所有上传的图片呢?

我需要更改 node.js 表上的某些内容还是只需要在 html 表上添加一些内容? 我用的是 node.js,multer 我需要更改 node.js 工作表上的某些内容还是只需要在 html 工作表上添加一些内容? 我使用了 node.js,multer

<!DOCTYPE html>
<head>
    <title>Profile form</title>
</head>
<body>

    <form method="POST" action="/profile-upload-multiple" enctype="multipart/form-data">
        <div>
            <label>Upload multiple profile picture</label>
            <input type="file" name="profile-files" required multiple  />
        </div>
        <div>
            <input type="submit" value="Upload" />
        </div>
    </form>

</body>
</html>

var express = require("express");
var multer = require("multer");
var port = 3000;

var app = express();

var storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, "./uploads");
  },
  filename: function (req, file, cb) {
    cb(null, file.originalname);
  },
});
var upload = multer({ storage: storage });

/*
app.use('/a',express.static('/b'));
Above line would serve all files/folders inside of the 'b' directory
And make them accessible through http://localhost:3000/a.
*/
app.use(express.static(__dirname + "/public"));
app.use("/uploads", express.static("uploads"));

app.post(
  "/profile-upload-single",
  upload.single("profile-file"),
  function (req, res, next) {
    // req.file is the `profile-file` file
    // req.body will hold the text fields, if there were any
    console.log(JSON.stringify(req.file));
    var response = '<a href="/">Home</a><br>';
    response += "Files uploaded successfully.<br>";
    response += `<img src="${req.file.path}" /><br>`;
    return res.send(response);
  }
);

app.post(
  "/profile-upload-multiple",
  upload.array("profile-files", 12),
  function (req, res, next) {
    // req.files is array of `profile-files` files
    // req.body will contain the text fields, if there were any
    var response = '<a href="/">Home</a><br>';
    response += "Files uploaded successfully.<br>";
    for (var i = 0; i < req.files.length; i++) {
      response += `<img src="${req.files[i].path}" /><br>`;
    }

    return res.send(response);
  }
);





app.listen(port, () => console.log(`Server running on port ${port}!`));
html node.js multer
© www.soinside.com 2019 - 2024. All rights reserved.