上传文件(项目实体的图像时),我想在/ public / images中为每个项目ID创建一个新的Linux子目录以存储其图像。但是,图像会立即保存到我指定的目录中项目ID(在请求中)。有没有办法做到这一点呢?
// Upload Image router.post("/project_image", function(req, res, next) { const form = new IncomingForm({ uploadDir: process.cwd() + "/public/images", // <- e.g. I would like this to be `/public/images/${req.body.project_id}` keepExtensions: true }); form.parse(req); let project; form.on("field", (name, value) => { project = JSON.parse(value); }); form.on("file", (field, file) => { let path = file.path; let fileName = path.substr(path.lastIndexOf("upload")); return req.db .from("projects") .where("id", "=", project.project_id) .update({ image: "/images/" + fileName }) .then(() => { return res.status(200).json({ message: "Image Upload Successful", error: false }); }) form.on("end", () => {}); });
谢谢。
[上传文件(项目实体的图像时),我想在/ public / images中为每个项目ID创建一个新的Linux子目录,以将其图像存储在其中。但是图像已保存...
我自己解决了以下问题。基本上,我将文件移动到其预期的目的地。