saveObject method
Future<String>
saveObject(
- String path,
- dynamic byteData, {
- String? extensionFormat,
- String? fileName,
- bool showProgress = false,
- BuildContext? context,
Uploads the selected bytes and returns file link Supports the extension format, if not set, will be set to application/octet-stream (bytes)
-
bool showProgress: if true, shows upload progress indicator and MUST set the
context
-
BuildContext context: if
showProgress
is true, MUST set thecontext
Implementation
@override
Future<String> saveObject(String path, byteData,
{String? extensionFormat,
String? fileName,
bool showProgress = false,
BuildContext? context}) async {
String fileNameAux =
fileName ?? DateTime.now().millisecondsSinceEpoch.toString();
Reference reference = FirebaseStorage.instance
.ref(path + fileNameAux + (extensionFormat ?? ""));
UploadTask? uploadTask;
switch (byteData.runtimeType) {
case String:
uploadTask = reference.putString(byteData as String);
break;
case Uint8List:
uploadTask = reference.putData(byteData as Uint8List);
break;
default:
uploadTask = reference.putData(byteData as Uint8List);
}
if (showProgress) {
if (context != null) {
await showDataUploadProgress(context, uploadTask);
} else {
if (kDebugMode) {
throw 'Must set context if show progress is true';
}
}
}
return await getDownloadUrl(uploadTask);
}