uploadFile method
Uploads a file from storage to Firebase Storage or optionally from local assets with assetPath
to Firebase Storage at uploadPath
.
Optional metadata can be provided with metadata
.
Implementation
Future<void> uploadFile(
{String assetPath = '', var metadata, String uploadPath = '/'}) async {
File file;
if (assetPath.isNotEmpty) {
file = await getFileFromAssets(assetPath);
await uploadTask(uploadPath, file, metadata: metadata);
} else {
FilePickerResult? result = await FilePicker.platform.pickFiles();
if (result != null) {
file = File(result.files.single.path!);
await uploadTask(uploadPath + '/' + result.files[0].name, file,
metadata: metadata);
} else {
// User canceled the picker
}
}
}