openKB
openKB copied to clipboard
Persist Images
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?
Same issue here. For me, on restarting dynos, entire data is lost.
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));
}
);