Muhummad Luqman
ย ยทย FlutterFlow Expert | Flutter | OpenAI | Software Engineer

Integrate Wasabi in Flutterflow

๐Ÿ“‚ 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!

6
2 replies