小编ear*_*yhe的帖子

如何使用flutter删除Firebase存储文件?

我是Flutter和Firebase的新手,所以请耐心等待.

我正在尝试使用Url文件删除Firebase存储中的文件.

我有文件的完整Url并删除除文件路径之外的所有字符.

然后我尝试删除该文件.从这里的其他答案开始,我使用命令; FirebaseStorage.instance.ref().child(filePath).delete()

以下是我的代码;

static void deleteFireBaseStorageItem(String fileUrl){

  String filePath = 'https://firebasestorage.googleapis.com/v0/b/dial-in-21c50.appspot.com/o/default_images%2Fuser.png?alt=media&token=c2ccceec-8d24-42fe-b5c0-c987733ac8ae'
                  .replaceAll(new 
                  RegExp(r'https://firebasestorage.googleapis.com/v0/b/dial-in-21c50.appspot.com/o/'), '');

  FirebaseStorage.instance.ref().child(filePath).delete().then((_) => print('Successfully deleted $filePath storage item' ));

}
Run Code Online (Sandbox Code Playgroud)

问题是文件永远不会被删除.

我想我已经找到了问题所在.

在该.delete()方法中,存在所需的'app'和'storageBucket'值.

当我运行此函数时,值为null.

见屏幕截图

我发现这令人困惑,因为在同一个文件中我看到了这个;

/// The [FirebaseApp] instance to which this [FirebaseStorage] belongs.
///
/// If null, the default [FirebaseApp] is used.
final FirebaseApp app;

/// The Google Cloud Storage bucket to which this [FirebaseStorage] belongs.
///
/// If null, the storage bucket of the specified [FirebaseApp] is used.
final String …
Run Code Online (Sandbox Code Playgroud)

dart firebase flutter firebase-storage

8
推荐指数
1
解决办法
1672
查看次数

Flutter Firebase cloud_functions 包抛出错误:INTERNAL

当尝试调用云函数时,我收到“CloudFunctionsException”

  • 异常的代码是“INTERNAL
  • 该消息是“响应不是有效的 JSON 对象。”

在此输入图像描述描述错误

重现 重现行为的步骤: - 我来自应用程序的调用是

 HttpsCallable _getName;

 _getName = CloudFunctions.instance.getHttpsCallable(functionName: 'getName',);


 try {
      HttpsCallableResult resp = await _getName.call(<String, dynamic>{'name': name,});
      Scaffold.of(context).showSnackBar(SnackBar(content: Text("${resp.data}")));
    } on CloudFunctionsException catch  (e) {
      showErrorMessage(context, 'Cloud functions exception with code: ${e.code}, and Details: ${e.details}, with message: ${e.message} ');
    } catch (e) {
      showErrorMessage(context, e.toString());
    }
Run Code Online (Sandbox Code Playgroud)
  • 我的云函数是这样写的:
exports.getName = functions.https.onCall((data, context) => {
    return {
        "data" : "You hit the call at least!"
    };
});
Run Code Online (Sandbox Code Playgroud)

预期行为 在我的响应中,我应该返回数据:“您拨打了测试电话”。相反,我收到错误

附加上下文 当我使用 HTTP 包调用相同的函数并使用“onRequest”在后端接收它时,它可以工作。

exports.getName …
Run Code Online (Sandbox Code Playgroud)

http dart firebase flutter google-cloud-functions

6
推荐指数
1
解决办法
950
查看次数