Tuesday 6 June 2017

Using multer with express in docker container

I developed an API with node js, express and multer for fileUploader. everything work well on local on my computer, but when i try to deploy on a docker container on my server the uploader file not work. I don't have error, in my client side the POST request return success 200 without erro but when i attach bach to my container, the files not exist...

Dockerfile:

FROM node:boron

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install

# Bundle app source
COPY . /usr/src/app
RUN mkdir public
RUN mkdir public/img

EXPOSE 8085
CMD [ "npm", "start" ]

Multer Conf:

// Upload dir for img
var storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, 'public/img')
  },
  filename: function (req, file, cb) {
    cb(null, file.originalname)
  }
});
var upload = multer({ storage: storage }).single('file');

I don't understand why that's not work on docker while the same code work fine in localhost.

Thanks for your answers.



via Cyril Connan

No comments:

Post a Comment