0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Heroku上のNode.js Expressでファイルアップロードを実装したときのError: ENOENT: no such file or directory

Posted at

Heroku上にデプロイした、Node.js Expressのmulterを使用したファイルアップロードで、エラーが出てアップロードできなかった話を共有します。

Logs

[Error: ENOENT: no such file or directory, open '/app/uploads/{filename}.jpg'] {
   errno: -2,
   code: 'ENOENT',
   syscall: 'open',
   path: '/app/uploads/{filename}.jpg',
   storageErrors: []
 }

Source

uploader.js

'use strict'
const express = require('express');
const router = express.Router();
const multer = require('multer');

const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, '/uploads/')
  },
  filename: function (req, file, cb) {
    cb(null, filename)
  }
})

const upload = multer({ storage: storage })

router.post('/', upload.single('file'), function (req, res, next) {
…  
(略)
…
});
module.exports = router;

対処法

Herokuでは /tmp/ 以下にしかファイルを保存できないらしい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?