๐ Upload Files to Wasabi Bucket in FlutterFlow
Wasabi is a cloud storage provider that offers low-cost, high-performance object storage similar to Amazon S3. A Wasabi bucket is a storage container where you can store and manage objects (files, images, videos, etc.), just like an Amazon S3 bucket.
๐น Prerequisites
Before starting, make sure you have:
โ
A Wasabi account with a storage bucket
โ
Access Key & Secret Key from Wasabi
๐ Step 1: Store API Credentials in the App State of Flutterflow
To keep credentials safe and accessible, store them in App State Variables and make them persistent.
Go to FlutterFlow โ App State and add:
wasabiAccessKey
(String)wasabiSecretKey
(String)wasabiBucketName
(String)
โ Mark them as persistent so they remain available across sessions.
โก Step 2: Add a Custom Action for File Upload
1๏ธโฃ Go to Custom Actions
in FlutterFlow
2๏ธโฃ Click on + Create
โ Name it UploadToWasabi
3๏ธโฃ Set Action Type โ Backend Call
4๏ธโฃ Add a Parameter โ Name it file (Type: FF Uploaded File)
5๏ธโฃ Paste the following code in the action:
import 'dart:io';
Future uploadFileToWasabi(FFUploadedFile file) async {
final String bucketName = FFAppState().bucketName;
final String url = 'https://${bucketName}.s3.wasabisys.com/${file.path}';
final String accessId = FFAppState().accessKey;
final String secret = FFAppState().secretKey;
try {
var request = http.MultipartRequest('PUT', Uri.parse(url))
..files.add(await http.MultipartFile.fromPath('file', file.path))
..headers.addAll({
'x-amz-access-id': accessId,
'x-amz-secret': secret,
});
var response = await request.send();
if (response.statusCode == 200) {
print('File uploaded successfully');
} else {
print('Failed to upload file: ${response.statusCode}');
}
} catch (e) {
print('Error uploading file: $e');
}
๐ Step 3: Call the Custom Action in Your App
1๏ธโฃ Add a File Picker in your FlutterFlow UI
2๏ธโฃ Call the Custom Action (UploadToWasabi
) in the Action Flow
3๏ธโฃ Pass the uploaded file as an argument
4๏ธโฃ Check if the upload is successful and display a success message
โ Important Notes
โ ๏ธ Make your Wasabi bucket public so files can be accessed after upload.
โก Ensure your API keys are stored securely (Avoid hardcoding in the app).
๐ ๏ธ You can modify the upload logic to handle different file types and permissions.
Thatโs it! ๐ฏ Now, your FlutterFlow app can seamlessly upload files to Wasabi Storage! ๐๐ฅ
๐ข Like, Comment, and Share if you found this helpful! ๐๐.
๐ฌ If you need any help, feel free to contact me!