Retrieves a collection of files that match the given form key. This method supports receiving a single file or multiple files from an < input type="file" multiple /> form control or from an AJAX upload.

This method can support both classic style Server based uploads:

<form action="FileUpload.wwd" method="post" enctype="multipart/form-data">
    <div class="fileUpload btn btn-primary">
                <i class="fa fa-upload"></i>
                Select file to upload
            <input type="file" id="upload" name="upload" 
                   class="upload" multiple accept="image/*" />
        <div id="filename"></div>
        <hr />
        <button type="submit" class="btn btn-primary"> Go</button>

or using AJAX style uploads:

<div class="container" style="padding-bottom:20px; border-bottom: solid 1px silver">
    <h3>Ajax File Upload</h3>
    <form id="ajaxForm" name="ajaxForm">
        <div class="fileUpload btn btn-primary">
                <i class="fa fa-upload"></i>
                Upload Image
                <i id="ajaxProgress" class="fa fa-spinner fa-spin" style="display: none"></i>
            <input type="file" id="ajaxUpload" name="ajaxUpload"
                    class="upload" accept="image/*" multiple />
    // Catch the file selection
    var files = null;
    $("#ajaxUpload").change(function (event) {
        files = event.target.files;

        // no further DOM processing

        // show spinner

            function uploadSuccess(data, textStatus, jqXHR) {
                var files = data;                            


                if (data.error)
                    toastr.error("Upload failed");

                toastr.success("Upload completed.");                            
                var images = "";
                for (var i = 0; i < files.length; i++) {
                    var file = files[i];                            
                    images += '<img src="../temp/' + file.filename + "' />"
            function uploadError(jqXHR, textStatus, errorThrown) {
                toastr.error("Upload failed.");


        Ajax Upload function

        Pass in from Change event of file upload control

        fileId  -  Id of the file Form vars
                    file results in (file0, file1, file2 etc)
        url     -  Url to upload to
        success -  success handler
                    data object of JSON result data from server
        error   -  error handler

    function uploadFiles(fileId, uploadUrl, success, error) {
        // Create a formdata object and add the files
        var data = new FormData();
        $.each(files, function (key, value) {
            data.append(fileId, value);

            url: uploadUrl,
            type: 'POST',
            data: data,
            cache: false,
            dataType: 'json',
            processData: false, // Don't process the files
            contentType: false, // Set content type to false!
            success: success,
            error: error


Return Value

Collection of files or an empty collection if no matching form vars are found. Collection objects have these properties:

  • Id - Form Id
  • Content - Binary content for the file uploaded
  • Filename - Filename of the file uploaded


The form variable for which to return files for


This method is bound by the 16 meg string limit in FoxPro so files larger than 16 megs will fail to upload. If you exceed the 16 meg string limit you may have to use the plUpload component instead.


The following is an example of a Process Method that handles one or multiple uploaded files to an Upload form variable either through an AJAX callback or by posting back to the server with the original page and string of image elements. The ajax code returns a JSON collection.


llAjax = Request.QueryString("type") == "ajax"

pcImageListHtml = ""

*** Files must use GetMultipartFile to retreive the file name as well
loFiles = Request.GetMultiPartFiles("Upload")

FOR EACH loFile IN loFiles
   *** Point upload at temp folder
   lcFileName = this.ResolvePath("~/temp/" +loFile.FileName)

   lcExt = LOWER(JUSTEXT(lcFileName))
   IF !INLIST(lcExt,"jpg","png","jpeg","gif")
      THIS.StandardPage("Upload Error","Only image files are allowed for upload.")
   IF LEN(loFile.Content) > 1500000
      THIS.StandardPage("File upload refused",;
                        "Files over 1.5meg are not allowed for this sample...<br/>"+;
                        "File: " + loFile.FileName)
   IF llAjax 
      loFile.Content = ""  &&amp; we don't need it on client
      pcImageListHtml = pcImageListHtml + ;
        [<img src="~/temp/] + loFile.FileName + [" />] + CRLF

*** delete files older than 10 minutes
DeleteFiles( this.ResolvePath("~/temp/*.*"),600)

IF llAjax
   *** Return collection of files
   Response.ContentType = "application/json"
   loSer = CREATEOBJECT("wwJsonSerializer")
   Response.Write( loSer.Serialize(loFiles) )


See also:

Class wwRequest

© West Wind Technologies, 1996-2024 • Updated: 03/07/2016
Comment or report problem with topic