Giter Site home page Giter Site logo

Comments (13)

Fishrock123 avatar Fishrock123 commented on April 27, 2024

@KIDx Could you please provide a more thorough test case?

from multer.

KIDx avatar KIDx commented on April 27, 2024

@Fishrock123 , Here is my code.

exports.dataUpload = function(req, res) {
  res.header('Content-Type', 'text/plain');
  if (!req.files || !req.files.data) {
    return res.end();
  }
  var path = req.files.data.path
  ,   fname = req.files.data.name
  ,   sz = req.files.data.size
  ,   pid = parseInt(req.query.pid, 10);
  var RP = function(s) {
    fs.unlink(path, function(){
      return res.end(s);
    });
  };
  if (!pid || !req.session.user) {
    return RP();
  }
  if (sz > 10*1024*1024) {
    return RP('2');
  }
  User.watch(req.session.user.name, function(err, user){
    if (err) {
      OE(err);
      return RP('3');
    }
    if (!user || !user.addprob) {
      return RP();
    }
    fs.readFile(path, function(err, data){
      if (err) {
        OE(err);            //!!!-----throw error here-----!!!
        return RP('3');
      }
      fs.mkdir(data_path+pid, function(){
        fs.writeFile(data_path+pid+'/'+fname, String(data).replace(/\r/g, ''), function(err){
          if (err) {
            OE(err);
            return RP('3');
          }
          return RP();
        });
      });
    });
  });
};

The error doesn't always happen.

from multer.

borodyadka avatar borodyadka commented on April 27, 2024

I have same problem. I think file does not exists when route is called.

from multer.

heyheyjp avatar heyheyjp commented on April 27, 2024

+1. There seems to be some race condition that needs to be addressed.

from multer.

hacksparrow avatar hacksparrow commented on April 27, 2024

Can you check if v0.1.2 fixed it?

from multer.

mperkh avatar mperkh commented on April 27, 2024

@hacksparrow We had this issue and since upgrading from v0.1.0 to v0.1.2 the issue never appeared again. Thanks for all your efforts!

from multer.

hacksparrow avatar hacksparrow commented on April 27, 2024

Thanks @mperkh. Let's wait for a confirmation from @KIDx and then close it.

from multer.

KIDx avatar KIDx commented on April 27, 2024

@hacksparrow thanks for waiting me.

I am not sure and I need more time, if the error appear, I will tell you at once.

Currently, I have some information below:

root@AY1404161244324771c6Z:~/ACdream# cat error.log
2014-07-12 13:13:50 [routes/index.js:1220:7]
Error: ENOENT, open 'uploads/1.cpp'

2014-07-15 23:25:04 [routes/index.js:2059:9]
Error: ENOENT, open 'uploads/d.cpp'

root@AY1404161244324771c6Z:/ACdream# npm ls | grep multer
├─┬ [email protected]
root@AY1404161244324771c6Z:
/ACdream# ll node_modules/multer/
total 44
drwxr-xr-x 3 root root 4096 Jul 15 09:16 ./
drwxr-xr-x 20 root root 4096 Jul 15 09:16 ../
-rw-r--r-- 1 root root 5755 Jul 13 22:30 index.js
-rw-r--r-- 1 root root 103 Jul 13 18:38 Makefile
drwxr-xr-x 5 root root 4096 Jul 15 09:16 node_modules/
-rw-r--r-- 1 root root 21 Jul 13 18:38 .npmignore
-rw-r--r-- 1 root root 1512 Jul 15 09:16 package.json
-rw-r--r-- 1 root root 8540 Jul 13 22:22 README.md

from multer.

hacksparrow avatar hacksparrow commented on April 27, 2024

@KIDx thanks, keep us posted.

from multer.

hacksparrow avatar hacksparrow commented on April 27, 2024

Multer now has test cases, try to write one to replicate the issue. In the meantime, I am closing this.

from multer.

afollestad avatar afollestad commented on April 27, 2024

I'm running into this issue now

from multer.

LinusU avatar LinusU commented on April 27, 2024

@afollestad could you please provide some code that exhibits the issue

from multer.

deje1011 avatar deje1011 commented on April 27, 2024

Hi there,
we are experiencing this issue in version 1.3.1. The file upload sometimes works, sometimes fails with this error:
ENOENT: no such file or directory, open '/tmp/uploads/xxx'

This is our code:

const multer = require('multer');
const upload = multer({ dest: '/tmp/uploads' });

FileRouter.post('/files',
    Authorization.roles.can('registered'),
    upload.array('file'),
    FileController.createFiles);

FileController.createFiles:

return Promise
    .map(req.files, file => {
        return fs.readFileAsync(file.path)
            .then(/*...*/);
    })
    .then(files => res.status(HTTPSTATUS.CREATED).json(files))
    // remove temp files
    .finally(() => {
        return Promise.map(req.files, ({ path }) => {
            return fs.unlinkAsync(path).catch(err => log.error(`Failed to delete temp upload file ${path}:\n${err.stack}`));
        });
    })
    .catch(next);

Does anyone have a solution for this?
Thanks,
Jesse

Edit: It tuns out the /tmp/uploads folder didn't exist on all server instances, that's why it sometimes worked and sometimes didn't.
Making sure the folder exists when deploying the server fixed the problem.
mkdir -vp /tmp/uploads/

from multer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.