openKB icon indicating copy to clipboard operation
openKB copied to clipboard

Persist Images

Open Richieval opened this issue 6 years ago • 2 comments

Hello, i 've deployed your kb system on heroku with a configured mongodb, images are saved on files system under "uploads". When the dyno sleep or is daily rebooted by heroku the images are lost. Any suggestion for persist images?

Richieval avatar May 09 '18 16:05 Richieval

Same issue here. For me, on restarting dynos, entire data is lost.

preeteshjain avatar Jun 13 '18 09:06 preeteshjain

We did something similar to this at Curri (where uploadFileToFirebase uploads the file to firebase):

router.post(
  '/file/upload_file',
  common.restrict,
  inline_upload.single('file'),
  async (req, res, next) => {
    if(req.file){
      // check for upload select
      const upload_dir = path.join(appDir, 'public', 'uploads', 'inline_files');
      const relative_upload_dir = req.app_context + '/uploads/inline_files';

      const file = req.file;
      const source = fs.createReadStream(file.path);
      const dest = fs.createWriteStream(
        path.join(upload_dir, file.originalname)
      );

      // save the new file
      source.pipe(dest);
      source.on('end', () => {});

      const uploadedFile = await uploadFileToFirebase(
        file.path,
        bucketPath
      );

      // delete the temp file.
      fs.unlink(file.path, err => {});

      // uploaded
      res.writeHead(200, { 'Content-Type': 'application/json' });

      res.end(JSON.stringify({
        filename: uploadedFile,
      }))

      return;
    }
    res.writeHead(500, { 'Content-Type': 'application/json' });
    res.end(JSON.stringify({ filename: 'fail' }, null, 3));
  }
);

briangonzalez avatar Feb 07 '20 22:02 briangonzalez