HTTP.GetFileSize

number HTTP.GetFileSize ( 

string   URL,

number   Mode = MODE_BINARY,

number   Timeout = 20,

number   Port = 80,

table    AuthData = nil,

table    ProxyData = nil,

function CallbackFunction = nil )

Example 1

nSize = HTTP.GetFileSize("http://www.mydomain.com/myfile.exe", MODE_BINARY, 20, 80, nil, nil, nil);

Gets the size of the file "myfile.exe" located at "http://www.mydomain.com" and stores it in the variable nSize.

Example 2

-- Settings for HTTP actions
sFileOnServer = "http://www.yourdomain.com/pub/file.ext";
sLocalFilePath = _TempFolder .. "file.ext";
nServerMode = MODE_BINARY;
nServerTimeout = 20;
nServerPort = 80;
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.GetFileSize(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 file size 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.Download(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 HTTP 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