1. Julián Tagarro
  2. PowerBuilder
  3. Monday, 22 January 2018 11:32 AM

Hi all,

I'm looking for the best way to upload a file to a web service. I've tried with blob data type on the server side (converted to Byte array by PB), and it works, but with very small files.

Both client application and web service are developed in PB 11.5

Any help ?

Thanks in advance.

Best regards.

__________________

Julián Tagarro

NeoSistemas SRL

Patrick Sohr Accepted Answer Pending Moderation
  1. Monday, 29 January 2018 09:08 AM
  2. PowerBuilder
  3. # 1
0
Votes
Undo

Hey we are using ole for all our webservice stuff, here is an example for our File Upload. We still getting some errors from the filereadex function. But for the most files everything is fine. Pro Tip of the day: Use a lot try catch if you work with the powerbuilder file functions and ole xmlhttp :)

choose case FileEncoding(gs_ablage_path + is_ablage) 
case EncodingANSI!
li_filenum = fileopen(gs_ablage_path + is_ablage, StreamMode!, Read!, LockWrite!, Append!, EncodingANSI!)
case EncodingUTF8!
li_filenum = fileopen(gs_ablage_path + is_ablage, StreamMode!, Read!, LockWrite!, Append!, EncodingUTF8!)
case EncodingUTF16LE!
li_filenum = fileopen(gs_ablage_path + is_ablage, StreamMode!, Read!, LockWrite!, Append!, EncodingUTF16LE!)
case EncodingUTF16BE!
li_filenum = fileopen(gs_ablage_path + is_ablage, StreamMode!, Read!, LockWrite!, Append!, EncodingUTF16BE!)
case else
li_filenum = fileopen(gs_ablage_path + is_ablage, StreamMode!, Read!, LockWrite!)
end choose
 
if li_filenum = -1 then
iou_kundenportal.uf_log(il_person_pers_id , '', 'Interner Fehler: fileopen fehlgeschlagen (Dokument konnten nicht gelesen werden)', '', '', 1, this.classname( ) + ' uf_post')
return -2
end if
 
if filereadex(li_filenum, lb_file) = -1 then
iou_kundenportal.uf_log(il_person_pers_id , '', 'Interner Fehler: filereadex fehlgeschlagen (Dokument konnten nicht gelesen werden)', '', '', 1, this.classname( ) + ' uf_post')
return -2
end if
 
if fileclose(li_filenum) = -1 then
iou_kundenportal.uf_log(il_person_pers_id , '', 'Interner Fehler: fileclose fehlgeschlagen (Dokument konnten nicht gelesen werden)', '', '', 1, this.classname( ) + ' uf_post')
return -2
end if
 
ls_adress = iou_kundenportal.is_kundenportal_domain + 'kundenportal/api/dokument_file/' + string(il_kundenportal_id)
lole_xmlhttp.open("PUT", ls_adress, false)
lole_xmlhttp.setRequestHeader("Authorization", "Token " + ls_token )
lole_xmlhttp.setRequestHeader("Content-Type", "*/*; charset=utf-8" )
lole_xmlhttp.setRequestHeader("Content-Disposition","attachment; filename=" + toolbox.uf_cleanfilename(extractfilename(is_ablage)))
lole_xmlhttp.setRequestHeader("Content-Length", string(len(lb_file)) )
lole_xmlhttp.send(lb_file)
 
ls_response = lole_xmlhttp.responsetext
 
choose case lole_xmlhttp.status
Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Tuesday, 23 January 2018 13:53 PM
  2. PowerBuilder
  3. # 2
0
Votes
Undo

You can use PostURL to post a binary file to a webpage if the webpage is coded to accept it. The webpage could write the data to a file on the webserver where the webservice can find it.

Comment
Hi Roland,



Thanks for the advise. I will give it a try.



Some idea came up (I don't know if this is going to work)



- Concatenate GetByte() to a string



- Send this string to the Web Service



- Parse the argument and SetByte() to a blob



Is there any improvement in PB 201x that allows file upload to a Web Service? This kind of operations are very usual and I think that PB should allow to develop applications that support them.



Regards.



______________



Julián Tagarro



NeoSistemas SRL

  1. Julián Tagarro
  2. Tuesday, 23 January 2018 16:39 PM
POSTURL that roland mentioned is already available.



the new HTTP object in R2 of PB 2017 will also allow you to send blobs via HTTP - you will have a lot more options and control with the new HTTP object:



https://www.appeon.com/developers/roadmap/consume-restful-web-services.html



 



 

  1. Mike S
  2. Tuesday, 23 January 2018 18:20 PM
Thanks Mike



Regards.



________________



Julián Tagarro



NeoSistemas SRL

  1. Julián Tagarro
  2. Tuesday, 23 January 2018 18:22 PM
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 22 January 2018 15:28 PM
  2. PowerBuilder
  3. # 3
0
Votes
Undo

Hi Julian;

   How about either a) FTPing the files to a landing pad on the Web Service server or b) uploading the file to a BLOB data type in a DB. Then call the WS to process the uploaded file from either A or BÉ

Food for thought.

Regards ... Chris

Comment
Hi Chris !!



Thanks for your response. 



a) I would really like to avoid FTP because it implies eventual firewall configurations, traffic limitations of some ISP's, etc.



b) The client will be installed on several servers (in different locations) and it will upload some compressed txt files to the Web Service located in a cloud server. Then, the Web Service will extract this files and load them to a database to do some proccessing. There is no connection other than that between client and WS.



Some ideas ? 



Best regards.



__________________



Julián Tagarro



NeoSistemas SRL

  1. Julián Tagarro
  2. Monday, 22 January 2018 18:33 PM
Sorry .. no further ideas.



 



However, since small files work - why the question?



Is performance an issue or file size limitation?



 

  1. Chris Pollach @Appeon
  2. Monday, 22 January 2018 20:30 PM
Size limitation. A 100k files implies an array of 100.000 rows.



Hard to believe there is no way out.



Thanks anyway Chris.



Regards

  1. Julián Tagarro
  2. Monday, 22 January 2018 23:40 PM
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.