小编Bry*_*Cho的帖子

使用Node.js/Express和Mongoose在MongoDB中存储图像

目前我使用angular-file-upload处理图像上传,我只是将图像保存到服务器的文件系统并在HTML中引用它.但是,我想尝试将图像直接存储在我为博客文章定义的Schema中的数据库中.

var blogSchema = new Schema({
    title: String,
    author: String,
    body: String,
    likes: { type: Number, default: 0 },
    comments: [{ type: Schema.Types.ObjectId, ref: 'Comment' }],
    date: { type: Date, default: Date.now },
    imageURL: String   // instead of this

    image: // store it directly
});

"imageURL: String" stores the path to the image.
Run Code Online (Sandbox Code Playgroud)

我想做到这一点,我可以只有一个存储图像本身的字段.我以为我可能只是像我已经上传的那样上传图像,而是在上传图像后将其转换为以二进制(或其他形式)存储在Mongo中.这可能吗?

谢谢!

mongoose mongodb node.js

11
推荐指数
1
解决办法
5万
查看次数

标签 统计

mongodb ×1

mongoose ×1

node.js ×1