Announcement

Collapse
No announcement yet.

Downloading large file size using HTTP Download Secure

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Downloading large file size using HTTP Download Secure

    Hi,
    I'm trying to download a large file (around 12 GB). There is no problem with downloading but the info we get through the callback is wrong. Taken the below code from the documentation and the total file size it shows is only 2 GB, not 12 GB. Because of this, all other information is collapsing. Someone can help me on how to fix this?

    Code:
    -- Callback function for HTTP.DownloadSecure
    function DownloadCallback (nDownloaded, nTotal, TransferRate, SecondLeft, SecondsLeftFormat, Message)
    -- Convert total and downloaded bytes into formatted strings
    sDownloaded = String.GetFormattedSize(nDownloaded, FMTSIZE_AUTOMATIC, true);
    sTotal = String.GetFormattedSize(nTotal, FMTSIZE_AUTOMATIC, true);
    
    -- Output time left, formatted.
    StatusDlg.SetMessage("Currently downloading file . . . Time Left: " .. SecondsLeftFormat);
    
    -- Output formatted sizes to user through statusdlg status text
    StatusDlg.SetStatusText("Downloaded: " .. sDownloaded .. " / " .. sTotal);
    
    -- Set meter position (fraction downloaded * max meter range)
    StatusDlg.SetMeterPos((nDownloaded / nTotal) * 65534);
    end
    
    -- Set statusdlg title and message
    StatusDlg.SetTitle("Downloading . . . ");
    StatusDlg.SetMessage("Currently downloading file . . . ");
    
    -- Set meter range (max range = 65534)
    StatusDlg.SetMeterRange(0, 65534);
    
    -- Show the StatusDlg
    StatusDlg.Show(0, false);
    
    -- Download a file from the internet to the user's computer
    -- Uses DownloadCallback() as the callback function
    HTTP.DownloadSecure("https://dkz9tcs83ng3p.cloudfront.net/sermon-updates/2022/jan/jan_ctsermons_package_2022.rar", _TempFolder .. "\\update.exe", MODE_BINARY, 20, 443, nil, nil, DownloadCallback);
    
    -- Hide the StatusDlg
    StatusDlg.Hide();

  • #2
    Hi susan2012 ,
    Found this code, I have not tested

    Code:
    --------------------------------------------------------------------------------------------------
    -- This example is to know the size of a file from an external server.
    --------------------------------------------------------------------------------------------------
    function HTTPGetFileSizeCallback(Info)
    StatusDlg.Show();
    StatusDlg.SetTitle("Downloading file information...");
    StatusDlg.SetMeterRange(0, 100);
    StatusDlg.SetMeterPos(0);
    StatusDlg.SetMessage(Info);
    
    if Info == "Initializing..." then
    StatusDlg.SetMeterPos(25);
    elseif Info == "Connecting to server." then
    StatusDlg.SetMeterPos(50);
    elseif Info == "Connected to server." then
    StatusDlg.SetMeterPos(75);
    elseif Info == "Closing connection to server." then
    StatusDlg.SetMeterPos(100);
    elseif Info == "Connection closed with server." then
    StatusDlg.Hide();
    end
    end
    --To Use
    Code:
    local Origin = "https://dkz9tcs83ng3p.cloudfront.net/sermon-updates/2022/jan/jan_ctsermons_package_2022.rar"
    result = HTTP.GetFileSize(Origin, MODE_BINARY, 20, 80, nil, nil, HTTPGetFileSizeCallback);
    -- This dialog shows the size of the selected file.
    local Opp = Math.Floor(result/1024);
    Dialog.Message("Size", result.." Bytes\r\n"..Opp.." KB\r\n"..(Opp/1024).." MB");
    also here is the apz: Callback Functions.apz
    Cheers

    Comment


    • #3
      Hi @colc, thanks for your post. I tried with it and it doesn't help. It still returns the same 2 GB in bytes while getting the file size.

      Comment


      • #4
        AMS limit

        Comment


        • #5
          It can be achieved without too much trouble.

          Click image for larger version

Name:	SCRN-2022-03-11-01.png
Views:	168
Size:	28.8 KB
ID:	308284

          This uses a plugin, and in the callback function, instead of working with the default nTotal argument, you would use the value returned in the action as shown above, stored in "result" or whatever name you chose.

          Ulrich

          Comment


          • #6
            Hi @Ulrich, It worked perfectly with the download callback as well. Thanks a lot.

            Comment

            Working...
            X