问题
Recently a new version of firebase storage just came (5.0.1). There is a lot of changes. I can't seem to upload a photo and get the download URL of the photo. Can you provide a way to do it in firebase storage 5.0.1
回答1:
import 'package:firebase_storage/firebase_storage.dart' as firebase_storage;
for uploading file
Future<void> uploadFile(String filePath) async {
File file = File(filePath);
try {
await firebase_storage.FirebaseStorage.instance
.ref('uploads/file-to-upload.png')
.putFile(file);
} on firebase_core.FirebaseException catch (e) {
// e.g, e.code == 'canceled'
}
}
for getting download links:
Future<void> downloadURLExample() async {
String downloadURL = await firebase_storage.FirebaseStorage.instance
.ref('users/123/avatar.jpg')
.getDownloadURL();
// Within your widgets:
// Image.network(downloadURL);
}
visit for depth details about this on https://firebase.flutter.dev/docs/storage/usage
来源:https://stackoverflow.com/questions/64843474/how-to-upload-image-in-firebase-storage-5-0-1-with-flutter