【发布时间】:2019-04-20 06:42:33
【问题描述】:
路线-
app.post('/add-product',(req,res)=>{
var image=randomstring.generate({
length: 12
});
var form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files) {
var oldpath = files.pimage.path;
var newpath = __dirname;
var path=newpath.split('controllers');
path=path[0]+'/public/productimages/'+image+".jpg";
fs.readFile(oldpath, function (err, data) {
if (err) throw err;
// Write the file
fs.writeFile(path, data, function (err) {
if (err) throw err;
});
});
});
});
在将图像上传到 Heroku 服务器时遇到了一些问题,在 Localhost 上一切正常。但是在 Heroku 上,当我上传图片时,我的应用程序在这些行上崩溃了。
fs.writeFile(path, data, function (err) {
if (err) throw err;
});
Heroku 日志截图:
将“/public.....”更改为“public/productimages/....”后
我得到: 没有这样的文件或目录,打开'/app/public/productimages/8sRueNlG2k3F.jpg'
【问题讨论】:
-
您是否运行了 heroku logs --tail 以查看日志内容?
-
00:00 app[web.1]: /app/controllers/user.js:247 00:00 app[web.1]: if (err) throw err; 00:00 app[web.1]: ^ 00:00 app[web.1]: 00:00 app[web.1]: Error: ENOENT: no such file or directory, open '/app//public/productimages /F8MboSYV62SZ.jpg' 00:00 app[web.1]: npm 错误!代码 ELIFECYCLE 00:00 应用程序 [web.1]:npm 错误!错误号 1 00:00 应用程序 [web.1]:npm 错误! maalikk@1.0.0 开始:
node index.js00:00 app[web.1]:npm 错误!退出状态 1 00:00 app[web.1]: npm ERR! -
请附上日志截图。
-
@RohanDhar 请检查我已附上日志截图
-
@RohanDhar i.stack.imgur.com/tX0Ta.png
标签: node.js heroku formidable