它说 await 仅对 async 函数有效,但我已经将 async 字放在 (req,res,next) 之前,我编码错了吗?
const axios = require("axios");
const FormData = require("form-data");
const imageKit = async (req, res, next) => {
if (req.files) {
try {
const files = req.files;
const values = Object.values(files);
values.map((perArray) => {
perArray.forEach((item) => {
if (item.mimetype === "image/jpeg" || item.mimetype === "image/png") {
const newForm = FormData();
const encodedFile = item.buffer.toString("base64");
newForm.append("file", encodedFile);
newForm.append("fileName", item.originalname);
const encodedKey = Buffer.from(
process.env.IMAGE_KIT + ":"
).toString("base64");
const result = await axios({
method: "POST",
url: "https://upload.imagekit.io/api/v1/files/upload",
data: newForm,
headers: {
...newForm.getHeaders(),
Authorization: `Basic ${encodedKey}`,
},
});
}
});
});
} catch (error) {}
}
};