uploadString method

Future<FileMetadata> uploadString({
  1. required String filePath,
  2. required String string,
  3. String contentType = applicationOctetStreamType,
  4. UploadProgressCallback? onUploadProgress,
})

Uploads a file to the backend from a string.

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

Throws an ApiException if the upload fails.

Implementation

Future<FileMetadata> uploadString({
  required String filePath,
  required String string,
  String contentType = applicationOctetStreamType,
  UploadProgressCallback? onUploadProgress,
}) async {
  final file = http.MultipartFile.fromString(
    'file',
    string,
    filename: filePath,
    contentType: MediaType.parse(contentType),
  );

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