First uploaded file parses but next uploaded file does not parse
See original GitHub issueHello,
I’m trying to parse xlsx files into my database after uploading with multer. The first file uploaded has no issue being parsed and uploaded into SQL after initial server start but problem arises with the succeeding files coming in afterwards.
Main problem: new files after first not being parsed after uploading the first file.
My current code set up for the parsing looks like this:
export async function insertDbfHeader(headerPath: string, tableName: string) {
const mySQLPool = getMySqlPool(databaseName);
const connection = await mySQLPool.getConnection();
const workbook = XLSX.readFile(path.resolve(__dirname, headerPath), { cellDates: true });
const sheet_name_list = workbook.SheetNames;
const xlData = XLSX.utils.sheet_to_json(workbook.Sheets[sheet_name_list[0]]);
for (let i = 0; i < xlData.length; i++) {
const rowObject: any = xlData[i];
const values = Object.values(rowObject);
let date = moment(new Date(values[0] as any)).format("YYYY/MM/DD");
let savekey: any = values[20];
savekey = parseInt(savekey);
let ac_desc1 = values[5];
let ac_desc2 = values[6];
let cp_desc1 = values[10];
let cp_desc2 = values[11];
let cp_desc3 = values[12];
let facility = values[22];
const query = `INSERT INTO ${tableName} (AC_DESC1, AC_DESC2, CP_DESC1, CP_DESC2, CP_DESC3, SAVEKEY, FACILITY, DATE) SELECT * FROM (SELECT '${ac_desc1}' as v1, '${ac_desc2}' as v2, '${cp_desc1}' as v3, '${cp_desc2}' as v4, '${cp_desc3}' as v5, '${savekey}' as v6, '${facility}' as v7, '${date}' as v8 ) AS tmp WHERE NOT EXISTS (SELECT AC_DESC1, AC_DESC2, CP_DESC1, CP_DESC2, CP_DESC3, SAVEKEY, FACILITY, DATE FROM ${tableName} WHERE SAVEKEY = '${savekey}' AND AC_DESC1='${ac_desc1}' AND AC_DESC2='${ac_desc2}') LIMIT 1`;
connection.query(query, (error, result) => {
if (error) {
console.error(error);
return result;
}
});
}
Any guidance would be greatly appreciated. I’ve been stuck on this for too long.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Null in Parse JSON when Upload in Forms is Optional
Solved: I have a flow that is triggered when a user submits a response to a Microsoft Form. A user has the option...
Read more >Unable to upload file via File field · Issue #480 · parse ... - GitHub
I'm able to connect and modify any data in mongoDB, but File fiels does not work. It upon uploading it return {"error":"unauthorized"}.
Read more >How to handle uploading and parsing files in your frontend ...
The solution to this problem is to test the mocked API and make sure it matches what we expect from the real API....
Read more >Unable to upload files – Error parsing server response. - phpBB
My first guess would be that the phpbb/attachment/upload.php is corrupt/incomplete. Try reuploading that file. If that is the problem then ...
Read more >Formidable doesnt form.parse() when uploading a file in Nodejs
This solution worked for me, it might be helpful for other dev. ... function(req, res, next){ // the uploaded file can be found...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I figured it out it was definitely a SQL table structure set up and query method issue. Thanks for your help SheetJSDev!
Yes my query sends in the parsed data into mySQL but with each new upload the old info gets added including the new data leaving me with duplicates.
I’m currently trying to avoid this and insert only the newest rows coming in from each uploaded file.