uploadFile method

Future<MmUploadFile201Response?> uploadFile({
  1. String? channelId,
  2. String? filename,
  3. MultipartFile? files,
  4. String? channelId2,
  5. String? clientIds,
})

Upload a file

Uploads a file that can later be attached to a post. This request can either be a multipart/form-data request with a channel_id, files and optional client_ids defined in the FormData, or it can be a request with the channel_id and filename defined as query parameters with the contents of a single file in the body of the request. Only multipart/form-data requests are supported by server versions up to and including 4.7. Server versions 4.8 and higher support both types of requests. ##### Permissions Must have upload_file permission.

Parameters:

  • String channelId: The ID of the channel that this file will be uploaded to

  • String filename: The name of the file to be uploaded

  • MultipartFile files: A file to be uploaded

  • String channelId2: The ID of the channel that this file will be uploaded to

  • String clientIds: A unique identifier for the file that will be returned in the response

Implementation

Future<MmUploadFile201Response?> uploadFile({
  String? channelId,
  String? filename,
  MultipartFile? files,
  String? channelId2,
  String? clientIds,
}) async {
  final response = await uploadFileWithHttpInfo(
    channelId: channelId,
    filename: filename,
    files: files,
    channelId2: channelId2,
    clientIds: clientIds,
  );
  if (response.statusCode >= HttpStatus.badRequest) {
    throw MmApiException(response.statusCode, await _decodeBodyBytes(response));
  }
  // When a remote server returns no body with a status of 204, we shall not decode it.
  // At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
  // FormatException when trying to decode an empty string.
  if (response.body.isNotEmpty && response.statusCode != HttpStatus.noContent) {
    return await apiClient.deserializeAsync(
      await _decodeBodyBytes(response),
      'MmUploadFile201Response',
    ) as MmUploadFile201Response;
  }
  return null;
}