B4A Library ✨ Magic API Library: Build a Powerful Server-Side REST API with MySQL and File Management in Just 5 Minutes! 🚀

fernando1987

Active Member
Licensed User
Announcing Magic API Version 5: Revolutionize Your Database Management!

We are thrilled to unveil Magic API Version 5, now packed with even more powerful features to elevate your database management experience. This update introduces the brand-new MagicFiles module and several exciting additions, making this the most versatile release yet!


What’s New in Version 5?

1. Introducing the MagicFiles Module

The new MagicFiles module provides seamless file and folder management, allowing you to:

  • Upload Files: Effortlessly upload single or multiple files.
  • Download Files: Retrieve files from the server directly.
  • Manage Folders: Create, list, and delete folders with ease.
  • Advanced URI Support (B4A): Select and upload files directly using ContentChooser.
' Example - Upload a File Using ContentChooser:
Private Sub Button1_Click
If chooser.IsInitialized = False Then
chooser.Initialize("chooser")
End If
chooser.Show("[I]/[/I]", "Choose File")
End Sub

Sub chooser_Result(Success As Boolean, Dir As String, FileName As String)
If Success Then
MagicFiles.UploadFileUri(FileName, "new_file.jpg")
Else Log("No file selected")
End If End Sub

Sub MagicFiles_UploadResultUri(Success As Boolean, FileName As String)
If Success Then
Log($"File ${FileName} uploaded successfully"$)
Else Log("Error uploading file")
End If
End Sub


2. New InsertOrUpdateMapForColumnValue Method

Simplify your workflows with this powerful method that:

  • Checks if a record exists in the database by column value.
  • Updates the record if it exists or inserts a new record if it doesn’t.
' Example - Insert or Update a Record:
Dim userData As Map
userData.Initialize
userData.Put("name", "John Doe")
userData.Put("email", "john.doe@example.com")
userData.Put("age", 30)

MagicAPI.InsertOrUpdateMapForColumnValue("users", "email", "john.doe@example.com", userData)

Wait For MagicAPI_InsertOrUpdateMapForColumnValue(message As String, success As Boolean)

If success Then
Select Case message
Case "Insert"
Log("A new record was inserted.")
Case "Update"
Log("The record was updated.")
End Select
Else Log("Error performing the operation.")
End If


3. New InsertMultipleMaps Method

Boost your efficiency by inserting multiple records at once with a single method call.

' Example - Insert Multiple Records:
Dim records As List records.Initialize

Dim user1 As Map
user1.Initialize
user1.Put("name", "Alice")
user1.Put("email", "[EMAIL]alice@example.com[/EMAIL]")
user1.Put("age", 25)

Dim user2 As Map
user2.Initialize
user2.Put("name", "Bob")
user2.Put("email", "[EMAIL]bob@example.com[/EMAIL]")
user2.Put("age", 28)

records.AddAll(Array(user1, user2))

MagicAPI.InsertMultipleMaps(records, "users")

Wait For MagicAPI_Insertmaps(m As Map, success As Boolean)

If success Then
Log($"Record inserted: ${m}"$)
Else Log("Error inserting records.")
End If


Why Upgrade to Version 5?

Enhanced Productivity: New tools to manage files and records effortlessly.
Seamless Integration: Works flawlessly with your existing Magic API setup.
Intuitive Design: Designed to save you time and make your workflows smoother.


Examples and Documentation
To help you get started, detailed examples and full documentation for the new routines and the MagicFiles module have been added to Post 1 of this thread. Check them out to see how easy it is to integrate these features into your projects!


How to Update if You’re an Existing Customer
If you’ve already purchased Magic API, here’s how you can get Version 5:
Log in to your account.
Navigate to the downloads section.
Download the latest update.


Experience the Power of Magic API Version 5 Today!
Got questions? Need help? Feel free to comment below or contact our support team.
 
Last edited:

fernando1987

Active Member
Licensed User

Important Update for Magic API File Management

We’re introducing an enhanced file and folder management system with the latest version of Magic API! Here's how it works:


File and Folder Operations in Magic API

Default Folder: upload

  • All files and folders you create or interact with will be managed inside a new folder named upload.
  • This folder will be automatically created the first time you upload a file.
Location: The upload folder will be created in the same directory as the files.php script on your server.


Automatic Folder Creation

  • When you add a file to a specific folder, Magic API will automatically create the folder if it doesn’t already exist.
  • This ensures seamless operations, eliminating the need for manual folder setup.

Examples

Uploading a File to the Default Folder

When uploading a file without specifying a folder, it will be stored directly in the upload folder.

' Example - Upload to Default Folder:
MagicFiles.UploadFile(File.DirRootExternal, "example.txt")

Wait For MagicFiles_UploadResult(Success As Boolean, FileName As String)

If Success Then
Log($"File ${FileName} uploaded successfully to the 'upload' folder."$)
Else
Log("Error uploading the file.")
End If


Uploading a File to a Specific Folder

If you specify a folder, Magic API will automatically create it if it doesn’t exist.

' Example - Upload to Specific Folder:
MagicFiles.UploadFileToFolder(File.DirRootExternal, "document.pdf", "tasks", "report.pdf")

Wait For MagicFiles_UploadToFolderResult(Success As Boolean, FileName As String)

If Success Then
Log($"File ${FileName} uploaded successfully to the 'tasks' folder."$)
Else
Log("Error uploading the file.")
End If


Why This Update?

Automated Management: No need to manually create folders. Magic API does it for you!
Simplified Operations: Focus on your app logic while the API handles the backend file structure.
Consistency: All file operations are neatly organized within the upload folder.


Note

  • All file and folder operations (e.g., uploading, deleting, listing) will now occur inside the upload folder for better organization and security.
  • If you interact with a folder that doesn’t exist, it will be created automatically.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…