uploadFile static method
Implementation
static Future<String> uploadFile({
File? file,
Uint8List? data,
SettableMetadata? meta,
required String path,
required String userId,
Function(TaskSnapshot)? onUploading,
}) async {
// Image name
final storageRef = FirebaseStorage.instance;
String assetName =
'${userId}_${DateTime.now().millisecondsSinceEpoch.toString()}';
// Upload file
final UploadTask uploadTask = file != null
? storageRef.ref().child('$path/$userId/$assetName').putFile(file)
: storageRef.ref().child('$path/$userId/$assetName').putData(data!, meta);
if (onUploading != null) {
uploadTask.snapshotEvents.listen(onUploading);
}
final TaskSnapshot snapshot = await uploadTask;
String url = await snapshot.ref.getDownloadURL();
return url;
}