AJAX: get size of requested file?

Discussion and feedback on Construct 2

Post » Thu Dec 08, 2016 8:56 pm

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!
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Fri Dec 09, 2016 2:40 am

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.
B
92
S
32
G
109
Posts: 5,294
Reputation: 70,999

Post » Fri Dec 09, 2016 4:20 pm

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

R0J0hound wrote: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.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Fri Dec 09, 2016 7:56 pm

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.
B
92
S
32
G
109
Posts: 5,294
Reputation: 70,999

Post » Fri Dec 09, 2016 9:20 pm

@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)
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Sat Dec 10, 2016 10:26 am

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.
B
92
S
32
G
109
Posts: 5,294
Reputation: 70,999


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 7 guests