1
ユーザーが画像をアップロードした後にSharpを使用して画像のサイズを変更するという明示的なアプリがあります。 'npm start'を使用してアプリケーションを起動すると、問題なくイメージをアップロードできますが、PM2を使用してプロセスを管理すると、イメージはサーバーに保存されません。私はSharpを使用せずにそれらのサイズを変更することができます。私が救い出されないという鋭いコードを持っているときだけです。以下は私のコントローラのコードです。 Multerはフォームを処理しており、シャープは画像のサイズを変更しています。PM2でアプリを実行しているときに鮮明な画像アップローダーが動作しない
doNewRecipe: function(req, res) {
for (var key in req.body) {
req.body[key] = req.body[key] || undefined;
}
var body = _.pick(req.body, 'title', 'description', 'ingredients', 'instructions', 'yield', 'prep_time', 'cook_time', 'categoryId');
body.userId = req.session.user.id;
if (req.file) {
var tempPath = req.file.path,
ext = path.extname(req.file.originalname).toLowerCase(),
//targetPath = path.resolve(finalUploadPath + req.file.filename + ext);
targetPath = path.resolve(finalUploadPath);
fs.renameSync(tempPath, tempPath + ext);
var newFileName = req.file.filename + ext;
var imageFile = tempPath + ext;
body.image = newFileName;
sharp(imageFile)
.resize(450, 450)
.max()
.toFile('./public/finalUpload/' + newFileName, function(err, info) {
body.image = newFileName;
fs.unlinkSync(path.resolve(tempPath + ext));
db.recipe.create(body).then(function(recipe) {
res.redirect('/recipe/view/' + recipe.id);
}, function(e) {
console.log(e.message);
res.render('error', {message: e.toString()});
});
});
//fs.renameSync(tempPath, targetPath);
} else {
db.recipe.create(body).then(function(recipe) {
res.redirect('/recipe/view/' + recipe.id);
}, function(e) {
console.log(e.message);
res.render('error', {message: e.toString()});
});
}
},
PM2でアプリを起動するには、ecosystem.json設定ファイルを使用していますか? CWDパラメータを追加できます。 – Zauker
私は 'pm2 start bin/www'を使ってアプリを起動しています。 –
これは同じではありません。 pm2 start /my/path/app.js 次に cd/my/path; pm2 start app.js あなたのアプリの起動オプションでjsonファイルを生成し、 'cwd'(作業ディレクトリのパス)を追加することもできます。 – Zauker