Android Example [B4X] PocketBase - Deleting files


Please read the official documentation about deleting files in pocketbase:

There are several ways to delete files with the B4X-Pocketbase SDK.

Delete Specific Files from a Record (DeleteFiles)
Deletes a specific file or multiple files from a record.
B4X:
    Wait For (xPocketbase.Storage.DeleteFiles("dt_Task","77avq8zn44ck37m","Task_Image",Array As String("test_l586xluw7q.jpg"))) Complete (DatabaseResult As PocketbaseDatabaseResult)
    xPocketbase.Database.PrintTable(DatabaseResult)
Parameters:
  • CollectionName: The name of the collection where the record exists.
  • RecordID: The ID of the record that contains the file.
  • ColumnName: The name of the field where the file is stored.
  • DocumentNames: An array of file names to be deleted.
Delete Individual Files from a Multi-File Field
With this function you can delete several file columns at once.
B4X:
    Dim UpdateRecord As Pocketbase_DatabaseUpdate = xPocketbase.Database.UpdateData.Collection("dt_Task")
    UpdateRecord.Update(CreateMap("Task_Image-":"test_6byr5kmo3b.jpg")) 'If you want to delete individual file(s) from a multiple file upload field, you could suffix the field name with - and specify the filename(s) you want to delete
    Wait For (UpdateRecord.Execute("8u7928b58636n76")) Complete (DatabaseResult As PocketbaseDatabaseResult)
    xPocketbase.Database.PrintTable(DatabaseResult)
Parameters:
  • CollectionName: The name of the collection.
  • FieldName: The field that contains the file.
  • FileName: The specific file to be deleted.
  • RecordID: The ID of the record.
Description:
  • This method removes specific files from a multi-file upload field.
  • The - suffix is used to specify which file(s) should be deleted.
Delete All Files from a Field
Removes all files from a file field in a record.
B4X:
    Dim UpdateRecord As Pocketbase_DatabaseUpdate = xPocketbase.Database.UpdateData.Collection("dt_Task")
    UpdateRecord.Update(CreateMap("Task_Image":""))
    Wait For (UpdateRecord.Execute("8u7928b58636n76")) Complete (DatabaseResult As PocketbaseDatabaseResult)
    xPocketbase.Database.PrintTable(DatabaseResult)
Parameters:
  • CollectionName: The name of the collection.
  • FieldName: The field that contains the file.
  • RecordID: The ID of the record.
Description:
  • This method deletes all files associated with a specific field by setting its value to an empty string ("").

Conclusion

With these three methods, you can manage file deletions in PocketBase efficiently:

  1. DeleteFiles → Remove specific files using Storage.DeleteFiles().
  2. Delete Individual Files from Multi-File Fields → Use the - suffix in UpdateData.Update().
  3. Delete All Files → Set the field value to an empty string.
 
Top