var filePath = req.files.photo.path,
imageName = req.files.photo.name ,
basePath = path.join(rootDir, '/public/uploads/user/' + id),
baseThumbPath = basePath + '/thumbs';
fs.readFile(filePath, function (err, data) { //
if(err){
console.log("There was an error")
}
if(!imageName){
console.log("There was an error")
}else{
if (!fs.existsSync(basePath)) fs.mkdirSync(basePath);
var newPath = basePath + '/' + imageName;
fs.writeFile(newPath, data, function (err) {
if (!fs.existsSync(baseThumbPath)) fs.mkdirSync(baseThumbPath);
var thumbPath = baseThumbPath + '/' + imageName;
//执行到 这里 上传原文件是 没任何问题
//就是 执行到 下面 gm部分时 有10次有2~3次失败的
gm(newPath).options({imageMagick: true}).resize(120, 120).noProfile().write(thumbPath, function (err) {
if (!err) {
console.log('done');
}else{
throw err;
}
});
});
}
});
服务器是 linux , node.js 0.10.21 , imagemagick ,gm (从ng-cordova 上传的 相片)
一开始是 使用了 imagemagick wrapper 也出这个错误 后来 换了 gm 不过同样 出现 相同错误。请高手 帮忙 谢谢。