MSI Factory 2.3

HTTP.GetFileSizeSecure

HTTP.GetFileSizeSecure

This is the first topic This is the last topic  

HTTP.GetFileSizeSecure

This is the first topic This is the last topic  

OverviewExamples

number HTTP.GetFileSizeSecure (

string   URL,

number   Mode = MODE_BINARY,

number   Timeout = 20,

number   Port = 443,

table   AuthData = nil,

table   ProxyData = nil,

function CallbackFunction = nil )

Example 1

nFileSize = HTTP.GetFileSizeSecure("https://www.mydomain.com/myfile.exe", MODE_BINARY, 20, 443, nil, nil, nil);

Gets the size of the file "myfile.exe" on the secure Web site and stores it in the variable nFileSize.

Example 2

-- Settings for HTTP actions

sFileOnServer = "https://www.yourdomain.com/pub/file.ext";

sLocalFilePath = _TempFolder .. "file.ext";

nServerMode = MODE_BINARY;

nServerTimeout = 20;

nServerPort = 443;

tAuthData = nil;

tProxyData = nil;

 

 

-- Set the max bytes allowed without alerting the user to 2MB (2*1024*1024):

QuestionByteThreshold = 2097152;

 

-- Assume download should continue

bContinueDownload = true;

 

-- Get Filesize of file to be downloaded

FileSize = HTTP.GetFileSizeSecure(sFileOnServer, nServerMode, nServerTimeout, nServerPort, tAuthData, tProxyData, nil);

 

-- Check if filesize is unknown

if FileSize == -1 then

   -- Filesize is unknown, alert user

   choice = Dialog.Message("Alert", "Filesize is unknown. Continue Download?", MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON1);

   if choice == 7 then

       -- User chose not to continue with download

       bContinueDownload = false;

   end

-- Check if filesize is greater than threshold

elseif FileSize > QuestionByteThreshold then

   -- Filesize is larger than threshold, alert the user

   choice = Dialog.Message("Alert", "Filesize is greater than the threshold by " .. FileSize - QuestionByteThreshold .. " bytes. Continue Download?", MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON1);

   if choice == 7 then

       -- User chose not to continue with download

       bContinueDownload = false;

   end

end

 

 

-- Check if download should continue

if bContinueDownload then

   -- Download File, using built in status dialog

   StatusDlg.Show();

   StatusDlg.ShowCancelButton();

   HTTP.DownloadSecure(sFileOnServer, sLocalFilePath, nServerMode, sServerPass, nServerPort, tAuthData, tProxyData, nil);

   StatusDlg.Hide();

else

   -- Don't download file, alert user that download has been terminated

   Dialog.Message("Alert", "Download aborted by user");

end

Checks the size of a file on a HTTPS server to be downloaded.  If the file is larger than a predefined threshold, the user is asked if the download should continue.

See also: Related Actions


Learn More: Indigo Rose Software - MSI Factory - Buy Now - Contact Us