How to monitor a file transfer from web site

I have a method to import small graphic files (20-50 kB each) from an external web site using a http GET request and .getMediaData() function. The data is then written to a file using plugins.file.writeFile. The method works ok, unless I try to retrieve multiple files using a ‘for’ loop. In this case the downloaded files are not complete, I imagine because the loop leaves no time to the .getMediaData() function to complete the file transfer.

I could use a function to delay the execution of the loop for a few seconds, but how many: 5, 10, more? The exact amount would be a wild guess because of the uncertainties inherent to a web transfer. Is there a way to monitor the transfer so to know when the graphic data are completely transferred to the variable and this can be safely written to disk?

Thanks for any help.

You should investigate the “plugins.file.streamFilesToServer” and "“plugins.file.streamFilesFromServer” functions, or even the free UserManager plugin which also has stream to/from server file transfer functions.

I did consider plugins.file.streamFilesFromServer functions and the UserManager plugin, but, if I am not wrong, they can be used for transfers between a Servoy server and client, not from any web server. But if I am wrong I would like to know how to do this.

rioba

I see. I was thinking you were in Web Client, so streaming to the server, then down to the client, is the way to go. I recall doing something similar once using the file plugin but using a while loop to check for the file instead of a delay in a for loop. Maybe look at that as an option.