PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → [WX22] What is the best way to download a binary file via a webservice
[WX22] What is the best way to download a binary file via a webservice
Iniciado por guest, 26,ene. 2018 13:28 - 10 respuestas
Publicado el 26,enero 2018 - 13:28
Hi,

I changed all my FTP Download procedures in windev to httprequest.
I use a awp site and cut the file in pieces.

The code is:

WHEN EXCEPTION IN Deserialize(stMyDownload_Vorgang,bufBIN,psdBinary) //Datei öffnen nDateihandle=fOpen(stMyDownload_Vorgang.sDateiname,foRead) IF nDateihandle=-1 THEN stMyDownload_Vorgang.nStatus=5 //Fehler stMyDownload_Vorgang.sFehlermeldung="Fehler beim der Öffnen der Quelldatei ! "+CR+ErrorInfo(errFullDetails) stMyDownload_Vorgang.bErgebnis=False Serialize(stMyDownload_Vorgang,bufBIN,psdBinary) RESULT bufBIN END //Zeiger positionieren IF fSeek(nDateihandle,stMyDownload_Vorgang.nMove,fpBeginning)=-1 THEN stMyDownload_Vorgang.nStatus=5 //Fehler stMyDownload_Vorgang.sFehlermeldung="Fehler bei der Positionierung der Quelldatei ! "+CR+ErrorInfo(errFullDetails) stMyDownload_Vorgang.bErgebnis=False Serialize(stMyDownload_Vorgang,bufBIN,psdBinary) RESULT bufBIN END stMyDownload_Vorgang.sDaten=fRead(nDateihandle,nBlockgröße) stMyDownload_Vorgang.bufChecksumme=HashString(HA_MD5_128,stMyDownload_Vorgang.sDaten) stMyDownload_Vorgang.bErgebnis=True DO stMyDownload_Vorgang.sDaten="" stMyDownload_Vorgang.sFehlermeldung="Fehler beim Download Vorgang !"+CR+ExceptionInfo(errFullDetails) stMyDownload_Vorgang.bErgebnis=False END Serialize(stMyDownload_Vorgang,bufBIN,psdBinary) RESULT bufBIN
It works, but it is not so fast as it could be. Has anybody found a better way to transfer binary files via HTML in windev ?
Publicado el 26,enero 2018 - 13:35
Hi Michael,

in theory, if you are using a post type httprequest, you can transfer binary content directly (I haven't found the time to test that correctly yet)...

So putting your file in a buffer and sending it back 'as is' should be enough...

That part works fine on the server side, with a browser on the other side (I'm using that for the download part of my site), what I haven't tested is the httprequest part on the client side.

So, again in theory, as the content is sent as is, there is no size increase (serialize) and the speed should be maximum.


Best regards
Publicado el 26,enero 2018 - 13:51
Hi Fabrice,

my code at client side is:

cMyRequest is httpRequest cMyResponse is httpResponse cMyRequest..URL = sWebserviceAdresse+"/PLAN_IT_2015_WEB/DE/"+Replace("PAGE_"+sProzedurename,"_","-")+".awp" cMyRequest..Content=bufBIN cMyRequest..ContentType="text/xml" cMyRequest..TimeOut=10*60*1000 //10 min cMyResponse = HTTPSend(cMyRequest)
What should I change to change it to a "post" request ?

the help says:

: Optional character string (with quotes)

HTTP message that will be sent to the server. This parameter can be specified only for a request for sending messages (POST request). The message to send must comply with the HTTP protocol used. If this parameter is specified and if it is not empty, it is a POST request; otherwise, it is a GET request (everything else is automatic).

I don´t understand this ......
Publicado el 26,enero 2018 - 14:57
Hi Michael,

what the help means is that the switch for the post mode is simply to use that optional parameter to send your parameters to your awp page (instead of setting them in the URL)...

When you do that, the request is using the post protocol and you should get your file directly in the result of the query.

Another advantage of the POST mode is that it is NOT limited in the size of the packets transported, when the get mode is...

Best regards
Publicado el 26,enero 2018 - 15:05
Ok, thx.

Last question:

If the server sends the pure binary file back, how can I receive additional information like checksum, result etc at client side ?

Something like that:

buffer =file+";"+checksum+";"+true ?
Publicado el 26,enero 2018 - 15:52
Hi...

I would advise that you put everything at the beginning of the buffer, something like:
Buffer = Checksum=Value+CR+Result=True+cr+FileContent

this way, it's easy to get the position of the second CR, and use left and right to separate things

Best regards
Publicado el 26,enero 2018 - 15:54
Yes, sure. Many thx Fabrice
Publicado el 26,enero 2018 - 17:50
Hi Michael,

for webservice + json , the common method is convert the buffer to base64. if corruption, you won't be able to decode it back
Publicado el 26,enero 2018 - 18:05
Hi ccc,

yes, I use it (see my code in the first post)

I think, the result of serialize() from the awp site is a base64 string. The problem is, that this file is ~ 30 percent larger as the original file and so this transfer is slower as from a browser.

I am looking for a fast html based download between windev and the awp site from webdev with small overhead.
Publicado el 26,enero 2018 - 18:28
Michael,

you could compress the file first and decompress it at he client. It depends on the type of file if it will help you.
I use this for instance to 'download' sqlite database to android devices. These DB-file are zipped up to a rate of 60-90%
Publicado el 26,enero 2018 - 18:34
Hi Arie,

my files are most pdf, dwg, dgn files. Indeed I use the compression, but not in every case is that a solution.
I would preferred a "pure" download / Upload of binary files via HTML.