Web File Uploader

From Xojo Documentation

Revision as of 18:59, 15 February 2021 by Gperlman (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The File Uploader control allows users to make a list of files to upload to the web server. File Uploader has its own user interface that cannot be changed. The user can add select one or more files at once. To upload the files, you call the StartUpload method, usually from an accompanying Button.

Uploaded files larger than 256K are written directly to the temporary folder if it is writeable. The file is kept in memory if the temporary folder is not writeable or the file is 256K or smaller. For files kept in memory, be aware that the maximum available RAM you have on your web server will limit the size of files that can be uploaded.

Below is a list of commonly used events, properties and methods. For the complete list, refer to WebFileUploader in the Language Reference.


UploadFinished - Called when the files have finished uploading. The event provides an array of the uploaded files for you to loop through and process.


MaximumFileCount - Indicates the maximum number of files the user can upload at once.


StartUpload - Call this method to start uploading the files that were added to the control.

Uploaded File

When the UploadFinished event is called, the parameter contains an array of the uploaded files. You can loop through these files to read them in or so save them to permanent locations.

Below are common properties and methods. Refer to WebUploadedFile in the Language Reference for the complete list.


Data - The contents of the file.

File - A Folder Item that points to the file, if it was uploaded to the temporary folder.

Name - The name of the uploaded file.


Save - Use this method to see the uploaded file to a permanent location.


This code in the Pressed event handler for a Button starts uploading the files that have been added to the File Uploader:


After the upload has completed, you can process the files in the UploadFinished event handler. This code saves the uploaded files to the Documents folder:

Var bs As BinaryOutputStream
Var f As FolderItem

For Each file As WebUploadedFile In Files
f = SpecialFolder.Documents.Child(file.Name)
bs = BinaryStream.Create(f, True)
Catch e As IOException
// Error, skip file
End Try

However, it is simpler and uses less memory to just call the Save method of the uploaded file to save it to a permanent location:

Var saveFile As FolderItem
For Each file As WebUploadedFile In Files
saveFile = SpecialFolder.Documents.Child(file.Name)
Catch e As IOException
// File Error, skip file
End Try

Example Project

The WebFileUploader example shows you how to let the user choose files to add and then upload them.


See Also

WebFileUploader, WebUploadedFile classes; UserGuide:Web Files topic