downloadAttachment method

Future<String?> downloadAttachment(
  1. String emailId,
  2. String attachmentId, {
  3. String? apiKey,
})

Get email attachment bytes. Returned as octet-stream with content type header. If you have trouble with byte responses try the downloadAttachmentBase64 response endpoints and convert the base 64 encoded content to a file or string.

Returns the specified attachment for a given email as a stream / array of bytes. You can find attachment ids in email responses endpoint responses. The response type is application/octet-stream.

Parameters:

  • String emailId (required): ID of email

  • String attachmentId (required): ID of attachment

  • String apiKey: Can pass apiKey in url for this request if you wish to download the file in a browser. Content type will be set to original content type of the attachment file. This is so that browsers can download the file correctly.

Implementation

Future<String?> downloadAttachment(String emailId, String attachmentId, { String? apiKey, }) async {
  final response = await downloadAttachmentWithHttpInfo(emailId, attachmentId,  apiKey: apiKey, );
  if (response.statusCode >= HttpStatus.badRequest) {
    throw ApiException(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), 'String',) as String;

  }
  return null;
}