Uploading csv files for import into database

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Uploading csv files for import into database

Postby alasdairs » Fri Jan 12, 2024 11:36 am

Hiya,
I was wondering whether it's possible to set up a csv/xls(x) file upload in TiNG, that automatically processes all of data within the file for whichever table you select in the database.

I have set up a servoy extra - file upload component but am not sure what the accept value should be for .csv files. I have a rough idea about how I would go about processing the data once it's been uploaded, but am unsure about how to get the data post upload.

Thanks!
Alasdair
Software Engineer
alasdairs
 
Posts: 45
Joined: Wed Dec 27, 2023 10:06 pm
Location: The Internet

Re: Uploading csv files for import into database

Postby mboegem » Fri Jan 12, 2024 1:02 pm

Hi Alasdair,

You can just do something like this:
Code: Select all
function onActionUpload(event, dataTarget) {
   plugins.file.showFileOpenDialog(callbackUploadFile);
}

/**
* @param {Array<plugins.file.JSFile>} _aFiles
*/
function callbackUploadFile(_aFiles) {
   if(!_aFiles.length) {
      return;
   }
   
   // process the file(s)
}


So you will click a button that will have the onAction function attached.
Once the user uploads the file, the callback function will be called and you can process the file like you have in mind.

Hope this helps
Marc Boegem
Solutiative / JBS Group, Partner
Servoy Specialist
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image
User avatar
mboegem
 
Posts: 1752
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 24 guests