0

I'm using latest firebase_storage version now some methods and references of storage are updated ploadTask.onComplete does not support.

so how do I get uploaded pdf url?

Piece of code:

 Future<String> uploadPdfToStorage(File pdfFile) async {
    try {
      Reference ref = FirebaseStorage.instance.ref().child('pdfs/${DateTime.now().millisecondsSinceEpoch}');
    UploadTask uploadTask = ref.putFile(pdfFile, SettableMetadata(contentType: 'pdf')); 
    String downloadUrl = await (await uploadTask.onComplete).ref.getDownloadURL();
  


   final String url = await downloadUrl;


  print("url:$url");
  return  url;
    } catch (e) {
      return null;
    }
  }
1
  • What's wrong with the code you have now? If there is an error message, you should add that to the question. Commented Dec 24, 2020 at 21:33

1 Answer 1

1

Here's an edited code that should work with the latest firebase storage_package:

Future<String> uploadPdfToStorage(File pdfFile) async {
  try {
    Reference ref =
        FirebaseStorage.instance.ref().child('pdfs/${DateTime.now().millisecondsSinceEpoch}');
    UploadTask uploadTask = ref.putFile(pdfFile, SettableMetadata(contentType: 'pdf'));

    TaskSnapshot snapshot = await uploadTask;

    String url = await snapshot.ref.getDownloadURL();

    print("url:$url");
    return url;
  } catch (e) {
    return null;
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.