I use uploadify with express.js to upload video to node server, it work fine, but after I generate the video thumbnail I need to return the thumbnail path, here is what I did
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);
});
}
});
}
});
};
here is frontend code
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);
}
});
}
the
console.log(data.thum_src); // always end of "undefined"
but
console.log(data) ; //will output the json data like this
{
'thum_src':'path'
}
I don't get it ??? why can't I access thum_src like data.thum_src ???
well it looks like it's not a object but a string, weird
your response in the server code need to add header {Content-Type:'application/json'} or else the default is to interpret as text. or u can do JSON.parse(data) to convert the text to json object in front end.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.