It took me two days to track down file uploading code that actually works, and it was embedded within one of the demo apps available with each release.
I tried code from the documentation and even tried the offline help files. No dice.
The difference between the help files and the example project is that file and Files() are used in the help files code whereas Files() alone is used in the example project. Files() is the already-declared array of files that someone has uploaded and they are ready to be saved onto disk space. Within the help files, the variable file is undeclared (there is no code declaring files to be a variable) while during runtime, files is to be treated as an array.
The net result is that the help files code throws errors while the project code as found within the example projects works fine.
The code as presented below should be in the FileUploader control’s UploadComplete event handler.
It runs when a button or other control calls the FileUploader’s Upload method.
Dim source As Picture
Source: Xojo – Examples > Web > Controls > WebFileUploader
Dim pFile As FolderItem
Dim uFolder As FolderItem
uFolder = GetFolderItem(“Uploads”)
If Not uFolder.Exists Then
uFolder.CreateAsFolder
End If
For i As Integer = 0 To UBound(files)
Try
source = Picture.FromData(files(i).Data)
// Create a file on the server
pFile = uFolder.Child(files(i).Name)
source.Save(pFile, Picture.SaveAsPNG)
Catch e As UnsupportedFormatException
Continue // Skip this file
End Try
Next
NOTE: This code uses the syntax of version 2018r3 – An update was released changing the preferred declaration of variable command to Var from Dim. While Dim is not completely obsolete, it is depreciated.
~ This 27th of June, 2020.
###
You must log in to post a comment.