{curl 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 applet}

{paragraph
    This applet demonstrates including a file in an HTTP request.
    Selecting a file and clicking {bold Submit} will send the file
    to a server-side script on the Web server. This script will 
    respond by telling you how large the file was. Note that files
    larger than roughly one MB will be truncated to conserve bandwidth.
}

|| Holds the URL of the file the user wants to upload
{let my-file-url:#Url}
{let submit-button:CommandButton =
    {CommandButton
        enabled?=false,
        label="Submit",
        {on Action do
            || Add the file to the form
            {submit-button.form.add-file 
                "uploaded-file",
                || will not be null when Submit button is enabled
                {non-null my-file-url}
            }
            || Submit the request
            {submit-button.form.submit}
            set submit-button.enabled? = false
            set submit-button.label = "Submit"
            {submit-button.form.reset}
        }
    }
}

{HttpForm
    {url "http://www.curl.com/cgi-bin/file-upload.pl"},
    margin=6pt,
    method=HttpRequestMethod.post,
    encoding=HttpFormData.multipart-mime-type,
    {spaced-hbox
        {CommandButton
            border-style=BorderStyle.raised,
            label="Choose File",
            || Ask the user for a file.
            {on Action do
                set my-file-url = 
                    {choose-file title="Select a file to upload"}
                {if-non-null my-file-url then
                    || Display the name of the selected file
                    set submit-button.label = "Submit " & my-file-url.name
                    set submit-button.enabled? = true
                }
            }
        },
        submit-button
    }
}

{paragraph Go back to the {link href={url "examples.php"}, Demo Page}}

