file picker and CSV file
Posted: 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!
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!