uploadFileWithHttpInfo method

Future<Response> uploadFileWithHttpInfo({
  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.

Note: This method returns the HTTP Response.

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<Response> uploadFileWithHttpInfo({
  String? channelId,
  String? filename,
  MultipartFile? files,
  String? channelId2,
  String? clientIds,
}) async {
  // ignore: prefer_const_declarations
  final path = r'/files';

  // ignore: prefer_final_locals
  Object? postBody;

  final queryParams = <MmQueryParam>[];
  final headerParams = <String, String>{};
  final formParams = <String, String>{};

  if (channelId != null) {
    queryParams.addAll(_queryParams('', 'channel_id', channelId));
  }
  if (filename != null) {
    queryParams.addAll(_queryParams('', 'filename', filename));
  }

  const contentTypes = <String>['multipart/form-data'];

  bool hasFields = false;
  final mp = MultipartRequest('POST', Uri.parse(path));
  if (files != null) {
    hasFields = true;
    mp.fields[r'files'] = files.field;
    mp.files.add(files);
  }
  if (channelId2 != null) {
    hasFields = true;
    mp.fields[r'channel_id'] = parameterToString(channelId2);
  }
  if (clientIds != null) {
    hasFields = true;
    mp.fields[r'client_ids'] = parameterToString(clientIds);
  }
  if (hasFields) {
    postBody = mp;
  }

  return apiClient.invokeAPI(
    path,
    'POST',
    queryParams,
    postBody,
    headerParams,
    formParams,
    contentTypes.isEmpty ? null : contentTypes.first,
  );
}