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.