fileup method
Implementation
Future<String> fileup(
Uint8List file, {
String? filename,
String? bucket,
String? ext,
StreamUploadProgress? onprogress,
Uri? endpoint,
}) async {
final suffix = switch (ext) {
null || '' => '',
_ when ext.startsWith('.') => ext,
_ => '.$ext',
};
final uri = endpoint ?? this.endpoint ?? Uri.base.resolve('mpc/w');
final request = MultipartRequest('POST', uri);
if (bucket?.isNotEmpty ?? false) {
request.headers['mesh-bucket'] = bucket!;
}
request.files.add(
MultipartFile(
'f',
_track(file, onprogress),
file.lengthInBytes,
filename:
filename ?? 'mesh_${DateTime.now().millisecondsSinceEpoch}$suffix',
),
);
final response = await _client.send(request);
final body = await response.stream.bytesToString();
if (response.statusCode >= 300) {
throw Exception('HTTP ${response.statusCode}: $body');
}
return body.isEmpty ? body : body.substring(1);
}