uploadBytes method

Future<FileMetadata> uploadBytes({
  1. required String filePath,
  2. required List<int> bytes,
  3. String contentType = applicationOctetStreamType,
  4. UploadProgressCallback? onUploadProgress,
})

Uploads a file to the backend from a list of bytes.

If not provided, contentType defaults to application/octet-stream.

Throws an ApiException if the upload fails.

Implementation

Future<FileMetadata> uploadBytes({
  required String filePath,
  required List<int> bytes,
  String contentType = applicationOctetStreamType,
  UploadProgressCallback? onUploadProgress,
}) async {
  final file = http.MultipartFile.fromBytes(
    'file',
    bytes,
    filename: filePath,
    contentType: MediaType.parse(contentType),
  );

  return await _apiClient.postMultipart<FileMetadata>(
    _objectPath(filePath),
    headers: _session.authenticationHeaders,
    files: [file],
    responseDeserializer: FileMetadata.fromJson,
    onUploadProgress: onUploadProgress,
  );
}