1

I have been trying to store files to Firebase Storage but couldn't really get it. So, please help me solve this problem I have to store a single image file to Firebase Storage and then get the URL or the file and store it in Realtime Database, all for Flutter Web-App.

Thanks

These are the codes for selecting file

Future selectFile() async {
    final _picker = ImagePicker();
    var image;
    image = await _picker.pickImage(source: ImageSource.gallery);
    return image;
  }

These are the codes for storing File

Future addPhotoTStorage(File file) async {
    final storage = FirebaseStorage.instance;
    var snapshot = await storage.ref().child(file.path).putFile(file);
    String url = await snapshot.ref.getDownloadURL();
    return url;
  }
Uraam Asif
  • 67
  • 7
  • Could you provide more details on what's not working? Any errors? Were you at least able to successfully upload the file? – Omatt Feb 17 '22 at 08:41
  • Actually this works on phone app but doesn't really work for web. When i am running this project on web, this is what i'm getting (these are the some of the errors): Error: Unsupported operation: _Namespace at Object.throw_ [as throw] (http://localhost:55533/dart_sdk.js:5391:11) at Function.get _namespacePointer [as _namespacePointer] (http://localhost:55533/dart_sdk.js:60608:17) at Function._namespacePointer (http://localhost:55533/dart_sdk.js:58178:28) at Function._dispatchWithNamespace (http://localhost:55533/dart_sdk.js:58183:31) – Uraam Asif Feb 17 '22 at 10:17
  • I see. You might just need to configure CORS for your web app as mentioned in the [FlutterFire docs](https://firebase.flutter.dev/docs/storage/usage/#cross-origin-access-cors-for-web-only). – Omatt Feb 17 '22 at 10:48
  • Do you fix it? I am getting same error, namespace... – Just Apps May 11 '22 at 11:26

0 Answers0