Home > Enterprise >  Flutter _AssertionError when i use putFile
Flutter _AssertionError when i use putFile

Time:07-22

I get this error

enter image description here

Here is my upload function:

 Future uploadFile() async{  
    final path = "images/$email/";
    final file = File("/storage/sdcard0/Download/folder"); 
    final ref = FirebaseStorage.instance.ref().child(path);
    ref.putFile(file);
  }

CodePudding user response:

I also face the issue while uploading files using putFile() function. So I try this.

import 'package:firebase_storage/firebase_storage.dart' as prefixStorage;

final int timestamp = DateTime.now().millisecondsSinceEpoch;
final ImagePicker picker = ImagePicker();
final XFile? image = await picker.pickVideo(source:ImageSource.gallery);
final prefixStorage.Reference firebaseStorageRef = firebaseStorage
            .ref()
            .child('images')
            .child(
                '/$timestamp${image?.path.substring(image.path.indexOf('.'), image.path.length)}');
await firebaseStorageRef.putData(await image.readAsBytes());
final String? imageURL = await firebaseStorageRef.getDownloadURL();
  • Related