我使用带有 express.js 的 uploadify 将视频上传到节点服务器,它工作正常,但是在我生成视频缩略图后,我需要返回缩略图路径,这就是我所做的
exports.upload = function(req, res,next){
var tmp_path = req.files.product_video.path;
var target_path = 'F:/shopping/shop/' +req.body.shop_id+'/'+ req.files.product_video.name;
fs.rename(tmp_path, target_path, function(err) {
if (err) {
console.log(err)
}
else{
fs.unlink(tmp_path, function() {
if (err){
console.log(err)
}else{
exec("C:/ffmpeg/bin/ffmpeg -i shop/"+ req.body.shop_id+ '/' + req.files.product_video.name + " -ss 00:01:00.00 -r 1 -an -vframes 1 -s 250x150 -f mjpeg shop/"+ req.body.shop_id+ '/' + req.files.product_video.name + "_thumbnail.jpg", function(err){
// res.send({'thumb' : 'shop/'+ req.body.shop_id+ '/' + req.files.product_video.name + "_thumbnail.jpg",});
var data = {
'thum_src':'shop/'+ req.body.shop_id+ '/' + req.files.product_video.name + "_thumbnail.jpg"
}
res.send(data);
});
}
});
}
});
};
这是前端代码
function addVideo(){
$('#input_product_video').uploadify({
'formData':{'shop_id':$('#shop_id').val()},
'buttonText' : 'add video',
'fileSizeLimit' : '100MB',
'fileObjName' : 'product_video',
'uploader' : '/uploads',
'swf' :'/public/javascripts/lib/uploadify/uploadify.swf',
'onUploadSuccess':function(file,data){
console.log(data.thum_src);
}
});
}
这
console.log(data.thum_src); // always end of "undefined"
但
console.log(data) ; //will output the json data like this
{
'thum_src':'path'
}
没看懂???为什么我不能像 data.thum_src 一样访问 thum_src ???
好吧,它看起来不是一个对象,而是一个字符串,很奇怪