AJAX: get size of requested file?

0 favourites
  • 6 posts
From the Asset Store
Convert multiple Excel files into JSON files and import them into construct3.
  • Hey everyone,

    I'm using AJAX to download patches for my NW.js exported project.

    When downloading an update via AJAX, I'd like to give the user feedback on how far the download is, not only by the overall progress, but also by how much of the filesize has been already downloaded (X MB of Y MB).

    Since my patches' size isn't static, but varies with each release, I can't use a static number.

    So, the question is: is there any AJAX-built in possibility to get the size of the requested file?

    If there isn't one, I guess I'll have to set a server-sided key with the release's size.

    Thanks for any answer!

  • While the Ajax plugin doesn't provide the size it does give the progress of the download in percent. Shouldn't that be enough feedback for the user? You could figure out the rate of the progress and give the user an eta as well.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • R0J0hound yeah sure, I could create a server-sided value with the size and let the user download that info.

    I was just wondering whether there is any easier way in the AJAX plugin.

    You could figure out the rate of the progress and give the user an eta as well

    As soon as I have the filesize, I can do that, yeah.

    Thanks for the answer.

  • What the ajax plugin can do is all listed. You could google how it would be done via JavaScript. "Ajax file size" yielded an answer in the first three results. Next you could see if that can be duplicated with what the plugin provides or use the browser object to run that js directly. Since it's an asycronous thing you could make a C2 function be the callback when it finishes.

  • R0J0hound

    Huh, I'm not sure whether I fully understand what you are saying..Am not that familiar with javascript.

    And even if I manage to get a download with javascript, no idea how to use the download into C2.

    Anyways, I'm going with the server-sided value now.

    (Quick side-question: Does anything speak against downloading .exes over 1MB with AJAX and writing them to disk with NW.js? If that's too complicated, nevermind, I'll open a new thread for that)

  • It's not too hard. The idea is you can request the header instead of the file and get the file size with that. It uses the "head" http request, which isn't implimented in the Ajax plugin (only "get" and post are implimented).

    Whatever works though.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)