node.js - 错误: ENOENT: 没有这样的文件或目录, 扫描目录 Kubernetes Pod
我正在尝试从我的 TypeScript/Express 应用使用 multer 上传文件。我已经在 Mac 本地测试过应用,它在 src 下有一个 uploads 文件夹时运行良好。它在本地 Docker 容器中也运行良好,没有任何问题。但是,一旦我将应用部署到 Kubernetes,路径就无法使用。计划是如果 uploads 文件夹不存在,应用将使用 - 创建该文件夹。
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;
}
});
现在,我遇到了错误 - Error: ENOENT: 没有这样的文件或目录,scandir。
即使文件夹存在,并且我登录到 pod 终端并将文件夹权限更改为 777,子文件夹仍然无法创建。
有人能帮忙吗。