I'm using xlsx to read xlsx and convert to json.
this is my code :
exports.processingMasterFunder = async (filePath, masterFunderId, filename, done) => {
try {
// read spreadsheet file
const workbook = XLSX.readFile(filePath, {cellDates: true});
// read spreadsheet section A
const sectionA = workbook.Sheets[workbook.SheetNames[0]];
// convert sheet to json data section A
const outputA = XLSX.utils.sheet_to_json(sectionA);
...
It was work perfectly in my local, until I upload to staging the error is occured. error like this :
Error: ENOENT: no such file or directory, open '/app/uploads/New Funder Statement January 2022.xlsx'
3/28/2022 5:48:40 PM at Object.openSync (fs.js:497:3)
3/28/2022 5:48:40 PM at Object.readFileSync (fs.js:393:35)
3/28/2022 5:48:40 PM at read_binary (/app/node_modules/xlsx/xlsx.js:3160:44)
3/28/2022 5:48:40 PM at readSync (/app/node_modules/xlsx/xlsx.js:23293:69)
3/28/2022 5:48:40 PM at Object.readFileSync (/app/node_modules/xlsx/xlsx.js:23333:9)
3/28/2022 5:48:40 PM at Object.exports.processingMasterFunder (/app/helpers/processing.js:29:27)
3/28/2022 5:48:40 PM at /app/worker.js:16:14
3/28/2022 5:48:40 PM at Worker.<anonymous> (/app/node_modules/kue/lib/queue/worker.js:230:7)
3/28/2022 5:48:40 PM at Job.<anonymous> (/app/node_modules/kue/lib/queue/job.js:706:12)
3/28/2022 5:48:40 PM at multi_callback (/app/node_modules/redis/lib/multi.js:89:14)
3/28/2022 5:48:40 PM at Command.callback (/app/node_modules/redis/lib/multi.js:116:9)
3/28/2022 5:48:40 PM at normal_reply (/app/node_modules/redis/index.js:721:21)
3/28/2022 5:48:40 PM at RedisClient.return_reply (/app/node_modules/redis/index.js:819:9)
3/28/2022 5:48:40 PM at JavascriptRedisParser.returnReply (/app/node_modules/redis/index.js:192:18)
3/28/2022 5:48:40 PM at JavascriptRedisParser.execute (/app/node_modules/redis-parser/lib/parser.js:574:12)
3/28/2022 5:48:40 PM at Socket.<anonymous> (/app/node_modules/redis/index.js:274:27) {
3/28/2022 5:48:40 PM errno: -2,
3/28/2022 5:48:40 PM syscall: 'open',
3/28/2022 5:48:40 PM code: 'ENOENT',
3/28/2022 5:48:40 PM path: '/app/uploads/New Funder Statement January 2022.xlsx'
It's weird, xlsx can't read the file that I uploaded and save using multer, but can read the file that already available in path that I push from local. Multer already write the uploaded file to the path, It's proved by succesfully uploading the file to google cloud and i can download it again from google cloud. It's mean the file in the correct path.
it's just happen in my staging. On local, it's work after I upload file and save using multer, xlsx can read the file without error.
How to solve my problems ?