messages.downloadAttachmentBlobAndUrl()

Retrieve an attachment's blob and URL using messageId and attachmentId, which is useful for image attachments.

To tell if an attachment is an image, use:

const message = ...
const attachment = message.attachments[0]
const isImage = attachment.contentType.indexOf('image/') === 0

Definition

client.messages.downloadAttachmentBlobAndUrl(
messageId: string|Message,
attachmentId: string|number
):Promise<string,Error>

Parameters

ParameterTypeDescription
messageIdstring|MessageMessage ID
attachmentIdstring|numberAttachment ID

Response

An error will be thrown if any of the arguments are invalid.

Otherwise, once the returned Promise is resolved, you will have access to the attachment URL as a string

Example

const file = await client.messages.downloadAttachmentBlobAndUrl(
message.id,
message.attachments[0].id
);
console.log('attachment blob is', file.blob);
console.log('attachment URL is', file.url);

In your HTML (After making sure the URL is of an image attachment):

<img src="URL goes here" alt="attachment-image" />