I'm trying to upload files with multer
from my typescript/express app. I have tested the application locally on mac it's working fine with a folder uploads
under src
. It worked well for the Local docker container too without any issue. But, once I deploy it to Kubernetes the paths are not working. The plan is if the uploads
folder does not exist then the app will create the folder using -
const storage = multer.diskStorage({
destination: function(req: Request, file: Express.Multer.File, callback: any) {
// const _baseUploadPath: string = path.join('./src', '..', 'abc_uploads');
const _baseUploadPath: string = path.join('../', 'uploads');
const _folderIdentifier: string | undefined = RequestTracker.requestId;
const _tmpPath: string = path.resolve(_baseUploadPath, `_tmp_${_folderIdentifier}`);
fs.existsSync(_baseUploadPath) || fs.mkdirSync(_baseUploadPath);
fs.existsSync(_tmpPath) || fs.mkdirSync(_tmpPath);
callback(null, _tmpPath);
},
filename: function(req: Request, file: Express.Multer.File, callback: any) {
callback(null, file.originalname.substring(0, file.originalname.indexOf(".")) + path.extname(file.originalname));
return;
}
});
Now, I am getting the error - Error: ENOENT: no such file or directory, scandir
.
Even if the folder is present and I'm login to the pod terminal and change the permission of the folder as 777 still the sub folders not getting created .
Can anyone please help.