我创建了一个API,该API根据 req.body.ALBUM 中传递的数据创建一个文件夹,并将传递的数据插入数据库中,以便以后进行检索。
现在,它只是创建文件夹并在其中移动图像,但没有在数据库中插入文件夹名称。
router.post('/create/folder', (req, res) => {
let sql = "INSERT INTO GALLERY SET ALBUM = ?";
myDB.query(sql, [req.body.ALBUM], (err, results) => {
if (err) {
console.log(err);
} else {
myUploads(req, res, (error) => {
if (error) {
console.log(error);
} else {
req.files.forEach(element => {
/* moving the files from tmp folder to the created folder based on the ALBUM data. */
fse.move(`public\\tmp\\${element.filename}`, `public\\${req.body.ALBUM}\\${element.filename}`);
})
res.send("Success")
}
});
}
})
这是传递 ALBUM 名称和图像的代码片段:
uploadFile() {
var formData = new FormData();
formData.append("ALBUM", this.albumName);
for (let image of Array.from(this.image)) {
formData.append("files", image);
}
axios.post("http://localhost:9001/image/create/folder", formData);
},