file picker and CSV file

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
eddie9394
Posts: 22
Joined: Tue Aug 14, 2018 11:03 pm

file picker and CSV file

Post by eddie9394 » Tue Oct 09, 2018 7:57 am

I am working on a project that will allow users to upload a CSV file from their local drive, the server module will save the CSV content to a database table and return a list. What is the best way to do this?

When fooling around with the code, I ran into some interesting problem with the file picker and HTTPRequest

1) file Picker #File have different values when assign to different object type:

evtroutine handling(#FilePicker.FileSelected) file(#File)
#wk_BLOB := #File.Blob
#wk_String1 := #File.Blob
#ProcessCSV.Execute fileblob(#wk_blob) filestring(#wk_String1) datalist(#ListItems) status(#wk_Status)
endroutine

srvroutine name(ProcessCSV)
field_map for(*input) field(#WK_BLOB) parameter_name(FileBLOB)
field_map for(*input) field(#wk_String1) parameter_name(FileString)
list_map for(*output) list(#DataList) parameter_name(DataList)
field_map for(*output) field(#wk_Status) parameter_name(Status)

#SYS_APPLN.TraceMessageText( ("Filter Modual BLOB=[&1], FILESTRING={&2} ").Substitute( #wk_blob #wk_String1 ) )
#wk_Status := OK
endroutine

Server Trace file:
Filter Modual BLOB=[C:\Program Files (x86)\LANSA\run\web_upload\93595108-69f1-45a4-b5e1-b77bedeb2b41\CF1178F.CSV], FILESTRING={blob:http://localhost:8080/9edb597b-3601-488 ... 3e1c53e1c0}


2) I can put the URL "blob:http://localhost:8080/9edb597b-3601-488 ... 3e1c53e1c0" in local browser and it will open the CSV file with Excel, that confirmed the file is uploaded to "C:\Program Files (x86)\LANSA\run\web_upload\93595108-69f1-45a4-b5e1-b77bedeb2b41\CF1178F.CSV" but when i try to read it back in the server module with the HTTP Request, I got nothing!

srvroutine name(GetList)
field_map for(*input) field(#WK_BLOB) parameter_name(FileBLOB)
field_map for(*input) field(#wk_String1) parameter_name(FileString)
list_map for(*output) list(#DataList) parameter_name(DataList)
field_map for(*output) field(#wk_Status) parameter_name(Status)

#SYS_APPLN.TraceMessageText( ("Filter Modual BLOB=[&2], FILESTRING={&3} ").Substitute(#wk_blob #wk_String1 ) )

* Do the get request
#Request.Clear
#Request.DoGet url( #wk_string1)
* I even replace the #wk_String1 with http://www.google.com
* delay timer (1 to 10 seconds)
#ResponseText := #Request.Response.asString
#SYS_APPLN.TraceMessageText( ("Response=[&1]").Substitute( #ResponseText ) )
#wk_Status := OK
endroutine

Trace File: ResponseText=[]


Any help or suggestion?! THANKS!

dannyoorburg
Posts: 161
Joined: Mon Jan 04, 2016 9:50 am
Location: Australia

Re: file picker and CSV file

Post by dannyoorburg » Tue Oct 09, 2018 9:20 am

Hi,

I can tell you what I know. I'm not quite clear in how far you got in getting what you want.

- A BLOB field on the SERVER contains a path to a file on disk containing the data.
- A BLOB field in the BROWSER contains a (blob-)url to a piece of memory containing the data.

LANSA allows a BLOB to be assigned to a string because of some properties on some controls taking a URL (or a path) as a string, an example of this is the image control.

If you upload the string it becomes meaningless, that URL only has meaning on the CLIENT and only WITHIN that particular browser session.

If you upload a BLOB field however, LANSA will upload the data for you and store it in a temporary file on the server, while populating the BLOB field on the Server with the path to that file.

NOTE the word temporary, unless you then save the BLOB into a database (at which point LANSA will copy the data into the table), or you copy the data yourself by copying the file somewhere else, you're just hanging on to a path to a file that is to be deleted at the end of the Server Routine execution, as LANSA doesn't keep all BLOB data around forever.

Hope that helps,
Danny

eddie9394
Posts: 22
Joined: Tue Aug 14, 2018 11:03 pm

Re: file picker and CSV file

Post by eddie9394 » Wed Oct 10, 2018 12:26 am

Thank you for the information! I will continue to play with it.

eddie9394
Posts: 22
Joined: Tue Aug 14, 2018 11:03 pm

Re: file picker and CSV file

Post by eddie9394 » Wed Oct 10, 2018 8:24 am

I end up using BIF Transform_File, it work BUT it didn't process all the records in the CSV file because of funny character in the data content!

use builtin(TRANSFORM_FILE) with_args(#WRKLIST #FileName "O" "B") to_get(#RETNCODE)

Post Reply