HISE Logo Forum
    • Categories
    • Register
    • Login

    Images from server

    Scheduled Pinned Locked Moved Scripting
    imagesserver
    64 Posts 8 Posters 3.9k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • d.healeyD
      d.healey
      last edited by

      Seems I'm answering all my own questions tonight :p

      function downloadCallback()
      {
          if(this.data.finished)
          {
              Panel1.loadImage(f.toString(0), "dave");
              Panel1.repaint();
          }
      }
      
      1 Reply Last reply Reply Quote 0
      • Christoph HartC
        Christoph Hart @d.healey
        last edited by

        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.

        d.healeyD 1 Reply Last reply Reply Quote 1
        • d.healeyD
          d.healey @Christoph Hart
          last edited by

          @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.

          1 Reply Last reply Reply Quote 0
          • d.healeyD
            d.healey
            last edited by d.healey

            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 a for...in and no more timeout error.

            Christoph HartC 1 Reply Last reply Reply Quote 0
            • Christoph HartC
              Christoph Hart @d.healey
              last edited by

              @d-healey or use Engine.extendTimeout()

              1 Reply Last reply Reply Quote 1
              • d.healeyD
                d.healey
                last edited by d.healey

                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);
                            }
                                
                    });
                
                1 Reply Last reply Reply Quote 0
                • Christoph HartC
                  Christoph Hart
                  last edited by

                  I don‘t see the extend timeout call in the snippet ;)

                  Call it in the loop and you should be fine.

                  d.healeyD 1 Reply Last reply Reply Quote 1
                  • d.healeyD
                    d.healey @Christoph Hart
                    last edited by

                    @Christoph-Hart Oh ok, I was calling it at the start of on init

                    1 Reply Last reply Reply Quote 0
                    • d.healeyD
                      d.healey
                      last edited by d.healey

                      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! 🐕

                      5706ea93-3393-47ae-a1b5-6e8299abec72-image.png

                      1 Reply Last reply Reply Quote 2
                      • d.healeyD
                        d.healey
                        last edited by d.healey

                        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 same

                        reg 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);
                        
                        1 Reply Last reply Reply Quote 0
                        • d.healeyD
                          d.healey
                          last edited by

                          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?

                          1 Reply Last reply Reply Quote 0
                          • d.healeyD
                            d.healey
                            last edited by d.healey

                            This post is deleted!
                            1 Reply Last reply Reply Quote 0
                            • d.healeyD
                              d.healey
                              last edited by

                              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]);
                              
                              Y 1 Reply Last reply Reply Quote 2
                              • Christoph HartC
                                Christoph Hart
                                last edited by

                                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 the success flag set to true.

                                d.healeyD 1 Reply Last reply Reply Quote 1
                                • d.healeyD
                                  d.healey @Christoph Hart
                                  last edited by

                                  @Christoph-Hart Thanks, I'll try it out :D

                                  1 Reply Last reply Reply Quote 0
                                  • Y
                                    yall
                                    last edited by

                                    @d-healey
                                    i just tried your script, the download works but the images do not appear in hise. I created 5 images (empty).

                                    d.healeyD 1 Reply Last reply Reply Quote 0
                                    • d.healeyD
                                      d.healey @yall
                                      last edited by

                                      @yall What do you mean they don't appear?

                                      1 Reply Last reply Reply Quote 0
                                      • Y
                                        yall
                                        last edited by

                                        in hise, it does not appear.

                                        d.healeyD 1 Reply Last reply Reply Quote 0
                                        • d.healeyD
                                          d.healey @yall
                                          last edited by

                                          @yall Show me the code you are using to display the images.

                                          DanHD 1 Reply Last reply Reply Quote 0
                                          • Y
                                            yall @d.healey
                                            last edited by

                                            @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

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            22

                                            Online

                                            1.7k

                                            Users

                                            11.8k

                                            Topics

                                            102.6k

                                            Posts