【问题标题】:Reading data from Cloud Storage using Flutter web使用 Flutter Web 从 Cloud Storage 读取数据
【发布时间】:2020-07-25 15:41:35
【问题描述】:

我正在使用 Flutter Web 应用程序(.dart),目的是从Cloud Storage 读取数据。我试过了,但我一直为空。

loadFromStorage() async {
print("Calling cloud function...");
final ref = FirebaseStorage.instance.ref().child('/data/ecg/hp2-1B72D3/1584859928685.ecg').getData(100).then((data) =>
    setState(() {
      imageBytes = data.toString();
    })
);

print(imageBytes);

}

我做错了什么?

【问题讨论】:

    标签: flutter dart flutter-web


    【解决方案1】:

    您好,这是我在 web 上使用包 firebase 的方法

    Future<String> uploadImage(
          {@required Uint8List imageData, @required String productId}) async {
    //    print('FirebaseImageStorageRepositoryWeb.uploadImage() started');
    
        StorageReference ref = firebase.storage().ref('Products').child(productId);
        String imageUrl;
        await ref.put(imageData).future.whenComplete(() async {
          await ref.getDownloadURL().then((url) {
            imageUrl = url.toString();
    //        print('image url is :$imageUrl');
            return;
          }).catchError((e) {
    //        print('FirebaseImageStorageRepositoryWeb.uploadImage() error: $e');
          });
          return;
        });
    
        return imageUrl;
      }
    
      @override
      Future deleteImage({@required String productId}) async {
        StorageReference ref = firebase.storage().ref('Products').child(productId);
    
    
        ref.delete().whenComplete(() {
          return;
        }).catchError((e) {
          print('FirebaseImageStorageRepositoryWeb.deleteImage() error: $e');
        });
        return;
      }
    

    这是firebase_storage使用的设备版本

      final picker = ImagePicker();
    Future<String> uploadImage(
          {@required Uint8List imageData, @required String productId}) async {
    
    //    print('FirebaseImageStorageRepositoryDevice.uploadImage() started');
    
        String imageUrl;
        await ref.child('Products').child(productId).putData(imageData).onComplete.whenComplete(() async {
    //      print('FirebaseImageStorageRepositoryDevice.uploadImage() image uploaded');
          await ref.child('Products').child(productId).getDownloadURL().then((url) {
    //        print('FirebaseImageStorageRepositoryDevice.uploadImage() getting imageUrl');
            imageUrl = url;
    //        print('image url is :$imageUrl');
            return;
          }).catchError((e) {
    //        print('FirebaseImageStorageRepositoryDevice.uploadImage() error: $e');
          });
          return;
        });
    
        return imageUrl;
      }
    

    这应该会让你朝着正确的方向前进

    【讨论】:

      猜你喜欢
      • 2020-03-26
      • 2021-01-24
      • 2022-12-13
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      • 2015-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多