Home > OS >  CRUD folder in Supabase bucket using Flutter
CRUD folder in Supabase bucket using Flutter

Time:02-06

can I CRUD a folder to the Supabase bucket from flutter app using supabase_flutter package?

for example create folder inside 'my_bucket' bucket on Supabase storage and upload a file to it using the code bellow:

final bytes = File('path').readAsBytesSync();
  String link = '';
  final fileExt = path.split('.').last;
  final supabase = Supabase.instance.client; 
 try {
    await supabase.storage
        .from('my_bucket') // create folder from here
        .uploadBinary(
          'file.$fileExt',
          bytes,
          
        );

    link = await supabase.storage
        .from('my_bucket') // get alink for  the file 
        .createSignedUrl('file.$fileExt');
  } on PostgrestException catch (e) {
    print('ErrorSupa:${e.message}');
   
  }

CodePudding user response:

You can just pass the path to the file like the following, and necessary folders will be created automatically.

final bytes = File('path').readAsBytesSync();
  String link = '';
  final fileExt = path.split('.').last;
  final supabase = Supabase.instance.client; 
    await supabase.storage
        .from('my_bucket') // create folder from here
        .uploadBinary(
          'path/to/file/file.$fileExt',
          bytes,
          
        );

    link = await supabase.storage
        .from('my_bucket') // get alink for  the file 
        .createSignedUrl('path/to/file/file.$fileExt');
  • Related