WebFileUploader workflow questions

I’m designing a WebApp that will make heavy use of WebFileUploader, and could benefit from others’ experience.
The files being attached will be .PDF and .JPG/.PNG, and each roughly 300k to 3mb in size.
I’m new to WebFileUploader, but here’s what I’m envisioning (and where I could use advice) as the workflow:

  • User Drags or Selects the files, where their names will display in a list.
  • User can select item in list and rename it (what they want the uploaded file to be named).
  • User pressed button to .StartUpload
  • I’ll manage the UI so they see the progress and deal with errors.
  • …this is where I’m fuzzy on what to do next…
  • I use this event to trigger next-steps: .UploadFinished(files() As WebUploadedFile)
  • …and then I iterate over the array of WebUploadedFile(s) to process them.
  • …and I’d like to override the file naming before committing them the the file system or database.

What would be the best process for saving these files as blobs in an associated database? Any pointers or tips (or warnings) for traditional post-upload processing is appreciated!

First of all, I suggest copying the files from the location they’re in to another directory for processing. Like many other frameworks, Xojo will delete the file one the Uploaded event ends.

Also, keep in mind that the folder items that are attached to the uploaded items may not have the original filename. That’s why they’re included in the classes that you get, so you can rename them back to the original names if necessary.

Honestly, I’d suggest that you use a helper app for processing though.

So it’d be

  1. Copy the file to a processing directory
  2. Maybe write the “instructions” to a json array
  3. Launch helper app and have it load the instructions.
  4. Release the event.

Personally I store PDF files in a mysql database. A lot of people don’t want to use BLOB and prefer external storage on disk. But if BLOB typeexists it could (must) be used if needed.

I use those methods to convert files to blob and reverse:

Function PDFtoBlob(f as FolderItem) As String
  Var result As String
  Var bs As BinaryStream = BinaryStream.open(f)
  Var sBlock as string = bs.Read(bs.Length)
  bs.Close
  result = EncodeBase64(sBlock)
  Return result
End Function

Sub BlobtoPDF(PdfContents as String, f as FolderItem)
  Var mb as MemoryBlock
  mb=DecodeBase64(PdfContents)
  Var bs as BinaryStream = BinaryStream.Create(f,True)
  bs.Write(mb)
  bs.Close
End Sub

not blob, its Base64 string.
blob is just byes, raw file data, binary.

DatabaseColumn have a BlobValue
SelectSQL/ ExecuteSQL can handle it via value parameter

PostgreSQL have extra methods.
example for PostgreSQL image upload

Sub UploadFinished(files() As WebUploadedFile) Handles UploadFinished
  System.DebugLog CurrentMethodName
    
  'For Each f As WebUploadedFile In Files
  'System.DebugLog f.Name + " Size " + f.Size.ToString
  'f.Save(Session.Data.Path.Child(f.Name))
  'Next
    
  '---------------------------------------- Connect
  
  Var db As New MyDatabase
  
  '---------------------------------------- Large Objects
  
  db.BeginTransaction
  
  For Each f As WebUploadedFile In Files
    System.DebugLog f.Name + " Size " + f.Size.ToString
    
    Var obj_id As Integer = db.CreateLargeObject
    Var largeObject As PostgreSQLLargeObject = db.OpenLargeObject(obj_id)
    largeObject.Write f.Data
        
    Var obj_id_thumbnail As Integer = db.CreateLargeObject
    Var largeObject_thumbnail As PostgreSQLLargeObject = db.OpenLargeObject(obj_id_thumbnail)
    Var pic As Picture = Module1.Thumbnail(f.Data,128.0)
    largeObject_thumbnail.Write pic.ToData(Picture.Formats.JPEG,80)
        
    Var row As RowSet = db.SelectSQL("insert into files (obj_id,mime_type,name,datetime,data_id,obj_id_thumbnail) values($1,$2,$3,$4,$5,$6) returning files_id",obj_id,f.MIMEType,f.Name,DateTime.Now,0,obj_id_thumbnail)
    
  Next
  
  Try
    db.CommitTransaction
  Catch e As RuntimeException
    db.RollbackTransaction
    MessageBox e.Message
  End Try
  
  '----------------------------------------
  
  System.DebugLog "All Saved Database"
    
End Sub
1 Like

A huge thanks for every reponse here! I will be working on this thru the next week and likely using morsels of each response.

1 Like