uploadTextFile method
Uploads a text file to Cloud Firestore. If the gzipData
is set to
true
then the data will be encoded via GZIP before transmission and the
encoding will be set to 'gzip', otherwise the data will be sent with
vanilla UTF8 encoding and the encoding will be set to 'utf8'.
The children
must contain one or more path elements to the location of
the text file.
Implementation
Future<void> uploadTextFile(
List<String?> children,
String data, {
bool gzipData = true,
}) async {
var ref = storage.ref();
for (var child in children) {
ref = ref.child(child!);
}
var bytes = utf8.encode(data);
if (gzipData == true) {
bytes = gzip.encoder.convert(bytes);
}
try {
await ref.putData(
Uint8List.fromList(bytes),
SettableMetadata(
contentEncoding: gzipData == true ? 'gzip' : 'utf8',
contentType: 'application/json',
),
);
} catch (e, stack) {
_logger.severe('Error writing: $children', e, stack);
rethrow;
}
}