Xojo Web Apps: 2018r3 upload code that works.

View of the UploadComplete method, as shown in Isolation Mode.

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
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

Source: Xojo – Examples > Web > Controls > WebFileUploader

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.
###

About Amy Barnes

Author has extensive experience in Retail, including two years as a supervisor. Educated in Psychology, Financial Accounting, Criminal Justice, and Programming. Work experience in Law Enforcement, Security (IT), Programming (REALBasic, SQL, VB, JAVA), Retail.
This entry was posted in Apps, Images, News, Programming, Programming, ScreenShots, Software, Tech News, Technology, Xojo and tagged , , , , , , , , . Bookmark the permalink.

This site uses Akismet to reduce spam. Learn how your comment data is processed.