How to Download Data like image or file via URL(firebase-file-path) using Firebase Storage in flutter?

99封情书 提交于 2020-04-30 08:45:46

问题


From the firebase documentation I found this getReferenceUrl(url) method. I use this gs://app_id.appspot.com/users/0a7d99409c.jpg as parameter inside getReferenceUrl method.

  /// Creates a [StorageReference] given a gs:// or // URL pointing to a Firebase
  /// Storage location.
  Future<StorageReference> getReferenceFromUrl(String fullUrl) async {
    ....
    ..
  }
}

Use-Case: I upload the file in the storage and save the file location for future use. And when I have to download the file in future how can I use this saved file location to download that particular file? I tried via this code:

String fileLocation = 'gs://app_id.appspot.com/users/0a7d99409c.jpg';
FirebaseStorage storage = FireStorageService.getObject();
StorageReference storageReference = await storage.getReferenceFromUrl(fileLocation);

await storageReference.getDownloadURL().then((returnUrl) {
  print(returnUrl);
  print(returnUrl);
});

Error Messages

Message1: error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.

Message 2: Unhandled Exception: PlatformException(download_error, Object does not exist at location., null)

E/StorageUtil(10404): error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please    sign in before trying to get a token.
W/NetworkRequest(10404): no auth token for request
E/StorageException(10404): StorageException has occurred.
E/StorageException(10404): Object does not exist at location.
E/StorageException(10404):  Code: -13010 HttpResult: 404
E/StorageException(10404): {  "error": {    "code": 404,    "message":  "Not Found.  Could not get object",    "status": "GET_OBJECT"  }}
E/StorageException(10404): java.io.IOException: {  "error": {    "code": 404,    "message": "Not Found.  Could not get object",    "status": "GET_OBJECT"  }}
/flutter (22431): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)]             Unhandled Exception: PlatformException(download_error, Object does not  exist at location., null)
E/flutter (22431): #0      StandardMethodCodec.decodeEnvelope 
package:flutter/…/services/message_codecs.dart:569
E/flutter (22431): #1      MethodChannel._invokeMethod 
package:flutter/…/services/platform_channel.dart:156
E/flutter (22431): <asynchronous suspension>
E/flutter (22431): #2      MethodChannel.invokeMethod 
package:flutter/…/services/platform_channel.dart:329
E/flutter (22431): #3      StorageReference.getDownloadURL 
package:firebase_storage/src/storage_reference.dart:142
E/flutter (22431): #4      _AboutState._uploadFile 

来源:https://stackoverflow.com/questions/61302982/how-to-download-data-like-image-or-file-via-urlfirebase-file-path-using-fireba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!