Page 1 of 1

File upload with special characters

Posted: Fri Jul 19, 2024 6:18 pm
by Paulm
Hello,

We are working with a file picker (client side) and the built-in function STM_FILE_OPEN + STM_FILE_READ (server side) to upload and parse a text file.

When we write the parsed values to the IBM i tables, the special characters are not written correctly (see example hereunder).

We did not find a solution in the documentation or on the forum.

Is there a way to solve this ?

Example:

Uploaded text file (UTF-8 encoded)

"éé"
"êê"
"%%"
"µµ"
"ëë"
"ùù"
"$$"
"££"

Table content:
"éé"
"êê"
"%%"
"µµ"
"ëë"
"ùù"
"$$"
"££"

Thanks in advance for your help! :D

Re: File upload with special characters

Posted: Fri Jul 19, 2024 7:18 pm
by kno_dk
see https://www.youtube.com/watch?v=FGoFamCnvJ8

it is RPG but maybe you can do the same in LANSA

Re: File upload with special characters

Posted: Mon Jul 22, 2024 9:42 am
by BrendanB
Paulm,

another way to read things:

Code: Select all

Mthroutine Name(ProcessFile)
Define_Map For(*INPUT) Class(#PRIM_DC.UnicodeString) Name(#inFile)

Define_Com Class(#PRIM_IOC.FileStream) Name(#InFileStream)
Define_Com Class(#PRIM_IOC.StreamReader) Name(#StreamReader) Stream(#InFileStream)

Define_Com Class(#PRIM_DC.UnicodeString) Name(#ReadString)

#InFileStream.Path := #inFile

Dowhile Cond(#StreamReader.TryReadLine( #ReadString ))

* process the #ReadString however you need to...
* you can use #ReadString.asNativeString   to convert to a standard alpha field...

Endwhile

Endroutine
note: streamreader is considerably faster than STM_FILE_OPEN + STM_FILE_READ when reading a file as well....

the path needs to be on the IFS for this to run...

B.

Re: File upload with special characters

Posted: Mon Aug 05, 2024 7:07 pm
by Paulm
Hi Brendan,

We were on vacation the last 2 weeks which is why I did not answer but thank you very much for your quick response.

I have tried your method and it works perfectly!

Thanks,

Paul