【发布时间】:2018-10-14 21:43:22
【问题描述】:
我使用邮递员为我创建的 API 保存了一张图片。 图片的保存方式是:
const newProduct = new Product({
name: req.body.name,
referenceId: createReferenceId(),
category: req.body.category,
image: {
data: fs.readFileSync(req.body.image),
contentType: "image/jpg"
},
metadata: req.body.metadata
});
newProduct
.save()
.then(product => res.json(product))
.catch(err => res.json(err));
我的猫鼬模式如下所示:
const ProductSchema = new Schema({
name: { type: String, required: true },
referenceId: { type: String, required: true },
category: { type: String, required: true },
image: { contentType: String, data: Buffer },
metadata: { type: String }
});
我存储的数据如下所示:
[255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 2, 1, 0, 100, 0, 100, 0, 0, 255, 225, 13, 5, 69, 120, 105, 102, 0, 0, 77, 77, 0, 42, 0, 0, 0, 8, 0, 7, 1, 18, 0, 3, 0, 0, 0, 1, 0, 1, 0, 0, 1, 26, 0, 5, 0, 0, 0, 1, 0, 0, 0, 98, 1, 27, 0, 5, 0, 0, 0, 1, 0, 0, 0, 106, 1, 40, 0, 3, 0, 0, 0, 1, 0, 2, 0, 0, 1, 49, 0, 2, 0, 0, 0, 20, 0, 0, 0, 11]
我想在 reactJS 中显示这个保存的图像?我很困惑我怎么能这样做。请帮忙。
【问题讨论】:
标签: javascript node.js reactjs react-native react-redux