-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
attachments: support attaching already-encoded base64 content #1552
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @davidjgoss, If you allow me to suggest a comment:
mediaType
in the context of the issue is mainly image/png
and data
is a string: so I expect that this string is already the result of a base64 encoding.
On line 54, I would do:
if ( typeof data === 'string' && mediaType.startsWith('image') {
// assume this is already base64 encoded
this.createStringAttachment(data, {
encoding: messages.Attachment.ContentEncoding.BASE64,
contentType: mediaType,
})
}
In this case there is no need to add an extra prefix, and it is just a matter of clarifying the documentation that in such case the string is expected to be already base64 encoded by the caller of the attach
method (as it was already the default behaviour in the v6
version)
@hdorgeval that's an option too, although even that has issues e.g. |
Fixes #1550.
After the refactor to accomodate messages, we made it impossible to attach content that was already base64 encoded, since passing a string and mime type to the
attach
function will cause it to be set as "identity".This makes it possible via a prefix on the mime type parameter e.g.
base64:image/png
. I'm not particularly wedded to this solution but it seems reasonable. Things we could do instead:attach
functionthis.attachBase64