Skip to Content
0
Oct 18, 2021 at 03:55 PM

How to convert CSV file in MDK Application, Attachment control

286 Views

Dear Experts,

We are in the process of kicking off new project, where we will build Mobile Offline APP using Mobile Services, MDK and I am currently reviewing certain technical challenges at the design stage.

One of the requirements of the project is Import data from CSV file and use that data to further process and save in backend OData. I have been reviewing controls available in the MDK reference library, as well as reading some posts/examples and seems like will use of 'Attachment' control to select the file for import and then write rule in Javascript to manually convert CSV file line by line.

So my questions is: How can I access content of the selected CSV file in String format?

I mean I have used some code examples from the web like below:

export default function OnPressImportar(context) {

    let appSettingsModule = context.nativescript.appSettingsModule;
    let fileSystemModule = context.nativescript.fileSystemModule;

    let lvAttachmentImportar = context.evaluateTargetPath('#Page:CrearRepuestosImport/#Control:FCAttachmentImportar');
    
    lvAttachmentImportar.getValue().forEach((attachment) => {
        let lvContent = attachment.content;
}

where at the end I get access to the content of the file selected at Attachment Control with variable lvContent, but it is in ArrayBuffer format like in screenshot below:

Can you please advise what methods I can use to convert this data to readable string and process further in my codes? Or any other suggestions/methodology/controls on how I could select a CSV file, convert it to readable table to process in my codes?

Thank you in advance!

Yergali