Upload images (bmp/jpg) and convert to png

Hi,

I can’t convert an image to png in order to upload it as small size file as it possible in xojo-cloud.
It should be something simple but something I missed.
Appreciate any help.

The conversion isn’t done on the browser. Use a webfileuploader to send it to the app and do the conversion in the UploadComplete event.

Greg, is there any web-xojo example? Can I use with any image or only with bmp/jpg?

found it but does not work. What am I doing wrong?

bmp is treated as unsupported format and saved as bmp
jpg is saved as jpeg… I don’t know if it nees to change the file extension
If the file is not a picture eg pdf it writes it succesfully as pdf

Dim uploadFolder As FolderItem
uploadFolder = UpLoadPage.MediaUserPath

Dim uploadedPicture As Picture
Dim savePicture As FolderItem
Dim source As Picture

For Each uFile As WebUploadedFile In files
Try

source = Picture.FromData(ufile.Data)

// Create a file on the server
savePicture = uploadFolder.Child(ufile.Name)
source.Save(savePicture, Picture.SaveAsPNG)

Catch e As UnsupportedFormatException

// Attempt to verify that the file is actually a picture. If it is not a picture, this will raise an exception and the file is skipped.
If uFile.File <> Nil Then
  uploadedPicture = Picture.Open(uFile.File)
 
Else
  uploadedPicture = Picture.FromData(uFile.Data)

End If

// Now save the file to disk in our upload folder
savePicture = uploadFolder.Child(uFile.Name)
uFile.Save(savePicture)

Continue // Skip this file

End Try

Next

Yes, you’ll need to change the file extension. Ufile.name will be whatever the original was. That said, not all platforms support bmp.