File upload with special characters

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
Paulm
Posts: 9
Joined: Mon Nov 28, 2022 5:58 pm

File upload with special characters

Post 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
kno_dk
Posts: 219
Joined: Tue Feb 23, 2016 12:00 am

Re: File upload with special characters

Post by kno_dk »

see https://www.youtube.com/watch?v=FGoFamCnvJ8

it is RPG but maybe you can do the same in LANSA
BrendanB
Posts: 134
Joined: Tue Nov 24, 2015 10:29 am

Re: File upload with special characters

Post 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.
Paulm
Posts: 9
Joined: Mon Nov 28, 2022 5:58 pm

Re: File upload with special characters

Post 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
Post Reply