Images from server
-
If I clear that list then it will download again. Does this list persist in the compiled plugin or is it just in HISE?
Nope, that's also the functionality in the plugin (the goal is to prevent downloading huge sample files again).
You can use
Server.cleanFinishedDownloads()
which does the same as clicking the button in the ServerController. -
@Christoph-Hart Oh excellent, that works out really well. I'll probably have a button the user can press to check for updates, and if there are new images that need downloading I can clear the cache.
-
Getting a couple of errors:
Unknown function 'setNumAllowedDownloads' Function / constant not found: Server.cleanFinishedDownloads
Also, what's the best way to download several images at once (or sequentially). I'm grabbing an array of image URLs from a server via GET then in the callback I'm running a loop over the array. In each iteration I'm running Server.downloadFile() but I'm getting execution timeout after a few iterations.
Update: I changed my
for
loop to afor...in
and no more timeout error. -
@d-healey or use Engine.extendTimeout()
-
I've set the timeout to 10 seconds but I'm still hitting the issue. Here's my call
Server.callWithGET("wp-json/my/v1/products", {}, function(status, response) { for (r in response) { var file = FileSystem.getFolder(FileSystem.Downloads).getChildFile(r.name + ".jpg"); var url = r.imageUrl.replace(Webstore.baseURL, ""); // Time out is on this line Server.downloadFile(url, {}, file, downloadCallback); } });
-
I don‘t see the extend timeout call in the snippet ;)
Call it in the loop and you should be fine.
-
@Christoph-Hart Oh ok, I was calling it at the start of on init
-
I'm going to try the exendTimeout thing now, but while I was waiting 7 whole minutes! for your reply I found another solution
var files = {}; var urls = {}; for (r in response) { files[r.name] = FileSystem.getFolder(FileSystem.Downloads).getChildFile(r.name + ".jpg"); urls[r.name] = r.image.replace(Webstore.baseURL, ""); } for (r in response) Server.downloadFile(urls[r.name], {}, files[r.name], downloadCallback);
Nice to see emojis working again :D :p ;)
Update: And I confirm the timeout method works!
-
I have a strange issue (bug maybe) with the this.data.finished clause being accessed more than once for each download.
Content.makeFrontInterface(600, 500); Console.clear(); reg count = 0; Server.setBaseURL("https://forum.hise.audio/uploads/profile"); const images = ["1-profileimg.jpg", "12-profileimg.jpg", "67-profileavatar.jpeg", "121-profileimg.jpg", "338-profileavatar.png"]; function downloadCallback() { if (this.data.finished) { Console.print(count + " : " + this.getDownloadedTarget().toString(1)); count++; } } reg f; for (i = 0; i < images.length; i++) { f = FileSystem.getFolder(FileSystem.Downloads).getChildFile(images[i]); Server.downloadFile(images[i], {}, f, downloadCallback); }
I thought it might be something to do with the loop or reusing the
f
variable so I also wrote it out the long way and the result is the samereg f0 = FileSystem.getFolder(FileSystem.Downloads).getChildFile(images[0]); Server.downloadFile(images[0], {}, f0, downloadCallback); var f1 = FileSystem.getFolder(FileSystem.Downloads).getChildFile(images[1]); Server.downloadFile(images[1], {}, f1, downloadCallback); var f2 = FileSystem.getFolder(FileSystem.Downloads).getChildFile(images[2]); Server.downloadFile(images[2], {}, f2, downloadCallback); var f3 = FileSystem.getFolder(FileSystem.Downloads).getChildFile(images[3]); Server.downloadFile(images[3], {}, f3, downloadCallback); var f4 = FileSystem.getFolder(FileSystem.Downloads).getChildFile(images[4]); Server.downloadFile(images[4], {}, f4, downloadCallback);
-
Any ideas? Is it possible that there is some shared data between the different instances of the downloadCallback so as each download finishes it's triggering the callback for other downloads?
-
This post is deleted! -
I think I've found a solution/workaround, recursion. Each download complete triggers the next download start.
Content.makeFrontInterface(600, 500); Console.clear(); Server.setBaseURL("https://forum.hise.audio/uploads/profile"); const images = ["12-profileimg.jpg", "67-profileavatar.jpeg", "121-profileimg.jpg", "338-profileavatar.png"]; function downloadCallback() { if (this.data.finished) { if (count < images.length-1) { count++; startNextDownload(images[count]); } } } inline function startNextDownload(fileName) { Console.print(fileName); local f = FileSystem.getFolder(FileSystem.Downloads).getChildFile(fileName); Server.downloadFile(fileName, {}, f, downloadCallback); } reg count = 0; startNextDownload(images[0]);
-
I fixed a few things about this, however it still is a bit glitchy if you're hammering the queue - I haven't been able to track down the reason, but sometimes the URL request returns a 404 despite the resource being available (I think it has to do with concurrent requests to the same server). This will make the callback fire multiple times for one download - however the
success
property is false for the requests that didn't work, so it's still executed once with thesuccess
flag set to true. -
@Christoph-Hart Thanks, I'll try it out :D
-
@d-healey
i just tried your script, the download works but the images do not appear in hise. I created 5 images (empty). -
@yall What do you mean they don't appear?
-
in hise, it does not appear.
-
@yall Show me the code you are using to display the images.
-
@d-healey said in Images from server:
I think I've found a solution/workaround, recursion. Each download complete triggers the next download start.
Content.makeFrontInterface(600, 500); Console.clear(); Server.setBaseURL("https://forum.hise.audio/uploads/profile"); const images = ["12-profileimg.jpg", "67-profileavatar.jpeg", "121-profileimg.jpg", "338-profileavatar.png"]; function downloadCallback() { if (this.data.finished) { if (count < images.length-1) { count++; startNextDownload(images[count]); } } } inline function startNextDownload(fileName) { Console.print(fileName); local f = FileSystem.getFolder(FileSystem.Downloads).getChildFile(fileName); Server.downloadFile(fileName, {}, f, downloadCallback); } reg count = 0; startNextDownload(images[0]);
@d-healey this :) in fact I'm trying but without really understanding for the moment
-
@d-healey Could I use something like this for Users to download HR1 files into their native OS downloads folder?
I've had to make a separate downloader anyway which links to a website but I'd rather it just download files without using a browser