以下是我的模特
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var dummySchema = new Schema({
name: {
type: String,
required: true
},
brand: {
type: String
},
class: {
type: String,
required: true
},
price: {
type: Number,
required: true
},
available: {
type: Boolean,
required: true
},
dateavailable: {
type: Date,
default:Date.now },
avatar:{
data:Buffer,
contentType:String
}
});
module.exports = mongoose.model('Dummy', dummySchema);
保存新实体的快速路线位于
之下app.post('/api/cars', function(req, res) {
var dummy = new Dummy();
dummy.name = req.body.name;
dummy.brand = req.body.brand;
dummy.class = req.body.class;
dummy.price = req.body.price;
dummy.available = true;
dummy.avatar.data = fs.readFileSync(req.body.avatar);
dummy.avatar.contentType="png";
dummy.save(function(err) {
if (err)
res.send(err);
res.send("sucess");
});
});
当我试图使用邮递员通过http / post插入数据时,如下所示
我收到以下错误
Error: ENOENT: no such file or directory, open 'E:\Fall_2015\SE\car_rental_software\server\https:\drive.google.com\file\d\0B9YLBjJ0zJ6YWDB4NUlFUThVS0E\view?usp=sharing'
<br> at Error (native)
<br> at Object.fs.openSync (fs.js:549:18)
<br> at Object.fs.readFileSync (fs.js:397:15)
<br> at E:\Fall_2015\SE\car_rental_software\server\index.js:88:32
<br> at Layer.handle [as handle_request] (E:\Fall_2015\SE\car_rental_software\server\node_modules\express\lib\router\layer.js:95:5)
<br> at next (E:\Fall_2015\SE\car_rental_software\server\node_modules\express\lib\router\route.js:131:13)
<br> at Route.dispatch (E:\Fall_2015\SE\car_rental_software\server\node_modules\express\lib\router\route.js:112:3)
<br> at Layer.handle [as handle_request] (E:\Fall_2015\SE\car_rental_software\server\node_modules\express\lib\router\layer.js:95:5)
<br> at E:\Fall_2015\SE\car_rental_software\server\node_modules\express\lib\router\index.js:277:22
<br> at Function.process_params (E:\Fall_2015\SE\car_rental_software\server\node_modules\express\lib\router\index.js:330:12)
<br> at next (E:\Fall_2015\SE\car_rental_software\server\node_modules\express\lib\router\index.js:271:10)
<br> at methodOverride (E:\Fall_2015\SE\car_rental_software\server\node_modules\method-override\index.js:79:5)
<br> at Layer.handle [as handle_request] (E:\Fall_2015\SE\car_rental_software\server\node_modules\express\lib\router\layer.js:95:5)
<br> at trim_prefix (E:\Fall_2015\SE\car_rental_software\server\node_modules\express\lib\router\index.js:312:13)
<br> at E:\Fall_2015\SE\car_rental_software\server\node_modules\express\lib\router\index.js:280:7
<br> at Function.process_params (E:\Fall_2015\SE\car_rental_software\server\node_modules\express\lib\router\index.js:330:12)
有人能告诉我如何在Mongoose中使用Node API保存图像吗?