我创建了一个GridFS并使用此图像上传了一个图像:
app.post("/upload", upload.single("photo"), function(req, res) {
res.redirect("/images");
})
我为用户提供了另一个模型:
var userSchema = new mongoose.Schema({
username: String,
password: String,
posts: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "fs"
}
]
});
我想将GridFS中的图像与登录的用户相关联。我可以获取用户ID。但我想知道如何获取上传图像的ID。请尽可能详细。我还是个菜鸟。谢谢
答案 0 :(得分:0)
上传的文件/照片的详细信息将附加到请求对象,您可以使用req.file对其进行访问
例如,要获取上传的图像的ID,您可以这样做
/*----------- Here the upload to server request will be -----------*/