【问题标题】:Issue uploading image file to Supabase storage with Flutter使用 Flutter 将图像文件上传到 Supabase 存储的问题
【发布时间】:2021-10-25 06:54:42
【问题描述】:

我在将图像从我的 Flutter 应用上传到 Supabase 存储时遇到问题。

基本上上传工作正常,但每次只上传一张空白图片。

这是我的代码。仅供参考,我正在使用颤振 image_picker 包来选择图像。

  File file = File(image.path);
  print('file $file'); // File: '/mydirectory/Library/Developer/CoreSimulator/Devices/98A6C1E0-14B0-481B-82CF-49803A0EB015/data/Containers/Data/Application/E07B33F6-7B5C-4EA0-AF78-84FF5A7E5BAD/tmp/image_picker_556716D5-69B1-485E-A7EE-39502A0F73C0-63547-0000EA70E7438D43.jpg'

  // Upload file to bucket "public"
  file.writeAsStringSync('File content');
  final storageResponse =
      await supabase.storage.from('public').upload(image.name, file);
  print('upload response : ${storageResponse.data}');

  // Get download url
  final urlResponse =
      await supabase.storage.from('public').createSignedUrl(image.name, 60);
  print('download url : ${urlResponse.data}');

storageResponse.data 和 urlResponse.data 都按预期输出(即从存储中获取响应)。

如前所述,它正在上传,但似乎上传的文件类型错误。我无法在存储中手动下载图像,也无法使用 url 查看它,我猜这是因为它已损坏。还说图像大小为 12 字节。

【问题讨论】:

    标签: flutter dart supabase


    【解决方案1】:
      file.writeAsStringSync('File content');
    

    看起来你正在用一个 12 字节的字符串覆盖文件

    【讨论】:

      猜你喜欢
      • 2021-09-13
      • 2021-07-03
      • 2020-04-30
      • 2022-07-25
      • 2018-10-24
      • 2019-01-22
      • 2019-08-31
      • 2022-12-16
      相关资源
      最近更新 更多