Read a file selected by the app's user


Ava Rashidi
Hi David,

I can read the file(.csv) that add to my app with file manager/other and read the data in the file, now I want to read the file that the user has chosen.

I use file control but I can not get the file path with [Input1.Url] or [Input1.Value], because I want to use it in FileRead action.

-Is this possible?(or should I use another method?)

Thanks

DecSoft

Hello Ava,

I am not sure if the Input File URL can be used with the FileRead action, maybe not, that is, maybe it's not the kind of URL expected for that action. If you want to try, please, do it in the Change or Read event of the Input File. Talking about the Read event of the Input File... may you can use it in order to read the selected file. Place the below code in the Read event of an Input File:

The above code take the Base64 of the file available in the Read event at the "Data" variable. We split this value with a comma, because what we wanted is the second item of the Array: the Base64 itself. With this we can use the "Base64ToStr" action in order to get the clear contents of the file.

Another possible way is to rely the read operation into the app's server, so, we can submit the file to the server, and, then the server can read it and send back to the app in a way ready to be used. This and the above paragraph propose an approach that no need any Cordova plugin.

Talking about Apache Cordova, maybe you can use a plugin to let the user to choose a file. I mean a different way than using an Input File control. On the other hand, you must look for the Cordova File plugin's documentation: remember that we can go beyond the FileRead action, for example, by directly use the Javascript API of the Cordova's plugin.

Maybe in this way you can read the Input File choosed file... or the result of the possible "dialog to choose a file" Cordova plugin. If you go ahead with this solution and need some particular help, just post it here and we will try to help you, Ava.



Ava Rashidi

Hi David,

Thanks for your very good description, I tested this option:

SplitStr "[Input1.Data]" "," "[FileDataArray]"

but when I select the file after that [Input1.Data] is empty(no data returns)!

So this line has error because my array does not have data

ArrayGetItem "[FileDataArray]" "1" "[FileBase64]"

-What's wrong with me?

Thank you for your help


DecSoft

Hello Ava,

It's quite rare. Are you sure that you are using the Read event of the Input File control and that that Input File's name is "Input1"?



Ava Rashidi

Hi David,

Oh yes, sorry I didn't use read event!

I got the result now ≧◔◡◔≦

I cannot thank you enough for helping me✿


DecSoft

Hello Ava,

Glad to know that you got it. :-)


Todo el mundo puede leer el foro de soporte de DecSoft para aprender del mismo, sin embargo, sólo los clientes de DecSoft pueden abrir nuevos hilos. Compre una o más licencias de productos de DecSoft y obtendrá este y otros beneficios.

Este sitio utiliza "cookies" útiles para almacenar sus preferencias.

Bien. Ocultar esta nota. Obtener más información.