0
NodeJSサーバー上のディスクにイメージ/ビデオを保存する最良の方法を探しています。 MongoDB。私はビデオでストリーミングをする必要もあります。何か案は?NodeJSサーバー上のディスクにイメージ/ビデオを保存し、MongoDBへの参照
NodeJSサーバー上のディスクにイメージ/ビデオを保存する最良の方法を探しています。 MongoDB。私はビデオでストリーミングをする必要もあります。何か案は?NodeJSサーバー上のディスクにイメージ/ビデオを保存し、MongoDBへの参照
がNPM
//モデル
'use strict';
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const DoctorSchema = new Schema({
fname: {type: String, required: true},
registrationNo: {type: String},
gender: { type: String},
//to save image's url
img: {type:String},
});
const DocModel = mongoose.model('DocModel', DoctorSchema);
module.exports = DocModel;
//route
const express = require('express'),
mongoose = require('mongoose');
const Doctor = mongoose.model('DocModel');
var bodyParser = require('body-parser');
var formidable = require('formidable');
var fs = require('fs');
const Router = express.Router();
//route to post
Router.post('/DoctorRegistration', (req, res) => {
//json object to save in database
var doc = new Doctor();
//declare variable to store other field values
var user = {};
var form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files) {
//assign field values to user
user = JSON.parse(fields.user);
//path to save image
var newpath = "";
//check whether file is null
if (files.file != null) {
var oldpath = files.file.path;
//save image in disk
newpath = './public/assets/docImg/' + user.fname+'.jpg';
fs.rename(oldpath, newpath, function (err) {
if (err) throw err;
});
//assign image path to save in database
doc.img = newpath;
}
doc.fname = user.fname;
doc.registrationNo = user.registrationNo;
doc.gender = user.gender;
//save object in database
doc.save(function (err) {
if (err) {
console.log(err.message);
res.json({success: false, message: 'User information
already exsits'});
}
else {
console.log(doc);
res.json({success: true, message: "user created"});
}
});
});
});
を使用して手ごわいインストール事前にありがとうございます