Created
September 5, 2023 20:49
-
-
Save dmslabsbr/0be288c1463fd44a6e345a35cf0a409c to your computer and use it in GitHub Desktop.
Functions to use Supabase Storage in flutterflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:supabase_flutter/supabase_flutter.dart'; | |
/** | |
deleta arquivo no supabase | |
*/ | |
Future<bool> deletaArquivoSupabase(String bucketName, String fileName) async { | |
print("Action: deletaArquivoSupabase"); | |
bool resultado = false; | |
try { | |
final supabase = Supabase.instance.client; | |
final storage = supabase.storage; | |
final List<FileObject> response = | |
await storage.from(bucketName).remove([fileName]); | |
for (FileObject file in response) { | |
print("file: ${file.name} apagado."); | |
resultado = true; | |
} | |
} catch (e) { | |
print("Exceção ao apagar arquivos: $e"); | |
} | |
return resultado; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:supabase_flutter/supabase_flutter.dart'; | |
/** | |
lista os buckets do supabase. | |
*/ | |
Future<List<String>> listaBucketsSupabase() async { | |
print("Action: listaBucketsSupabase"); | |
List<String> resultado = []; | |
try { | |
final supabase = Supabase.instance.client; | |
final storage = supabase.storage; | |
final List<Bucket> buckets = await storage.listBuckets(); | |
for (Bucket bucket in buckets) { | |
resultado.add(bucket.name); | |
print("Bucket: " + bucket.name + " id: " + bucket.id); | |
} | |
} catch (e) { | |
print('Erro ao listar buckets: $e'); | |
} | |
return resultado; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:supabase_flutter/supabase_flutter.dart'; | |
/** | |
Lista arquivos de um bucket hospedado no Supabase | |
*/ | |
Future<List<String>> listaArquivosSupabase(String bucketName) async { | |
// renomear o nome de um arquivo no supabase storage | |
print("Action: listaArquivosSupabase"); | |
List<String> resultado = []; | |
try { | |
final supabase = Supabase.instance.client; | |
final storage = supabase.storage; | |
final response = await storage.from(bucketName).list(); | |
// final arquivos = response.data as List<FileObject>; | |
for (FileObject file in response) { | |
print("file: ${file.name}"); | |
resultado.add(file.name); | |
} | |
} catch (e) { | |
print("Exceção ao listar arquivos: $e"); | |
} | |
return resultado; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:supabase_flutter/supabase_flutter.dart'; | |
/** | |
renomear o nome de um arquivo no supabase storage | |
*/ | |
Future<bool> trocaNomeArquivoSupabase( | |
String nome, String novoNome, String bucketName) async { | |
print("Action: trocaNomeArquivoSupabase 6"); | |
bool ret = false; | |
try { | |
final supabase = Supabase.instance.client; | |
final storage = supabase.storage; | |
print("Nome: " + nome + " para: " + novoNome); | |
//final Future<String> result = storage.from(bucketName).move(nome, novoNome); | |
final String result = await storage.from(bucketName).move(nome, novoNome); | |
print("result: " + result.toString()); | |
ret = true; | |
} catch (e) { | |
print('Erro ao renomear arquivo: $e'); | |
} | |
return ret; | |
} |
Faz algum tempo, mas sim. Lembrando que eles ficam com os nomes diferentes do que você usou para enviar.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
VocÊ conseguiu listar todos os arquivos de um folder?