我正在尝试在节点js上传视频,我有一些疑问。图像上传和视频上传是否相同,即用于视频上传的图片上传工作代码?
这是我的代码,
exports.uploadVideo = function( req, res ) {
upload_image = '';
upload(req,res,function(err){
if(err){
res.json({error_code:1,err_desc:err});
return;
}
var obj = req.body;
obj.video = upload_image;
if(obj.edit){
delete obj.edit;
updateBlog(req, res, obj, 'update');
} else {console.log('hi')
addVideo(req, res, obj);
}
});
};
var storage = multer.diskStorage({
destination: function (req, file, callback) {
callback(null, config.videoUploadPath);
},
filename: function (req, file, callback) {
var ext = '';
var name = '';
if(file.originalname){
var p = file.originalname.lastIndexOf(".");
ext = file.originalname.substring(p+1);
var firstName = file.originalname.substring(0, p+1);
name = firstName + '-' + Date.now();
name += '.'+ext;
}
upload_image += name;
upload_image += ',';
upload_image = upload_image.replace(' ', '');
callback(null, name);
}
});
var upload = multer({ storage : storage}).array('video');
根据我的路线,首先调用exports.uploadVideo()。我是全新的,有人可以帮帮我。谢谢。