-
Notifications
You must be signed in to change notification settings - Fork 630
Change CreateAttachment to stream data from disk when possible
#3322
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
Conversation
GnomedDev
left a comment
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.
I like this, but I have some concerns. Alongside the review comment, I dislike how a bunch of methods have been made async and falliable, instead of just taking the data.
Maybe we need to stop using CreateAttachment for these methods, taking a newtype around String if we want to enforce the base64 encoding with the type system? If so, please do this as a separate commit.
|
We could do that, unfortunately the data needs to be encoded as a Data URL, not just raw base64, and therefore needs to have a valid prefix like |
|
The newtype can enforce the prefix as well, I'm fine with that, that keeps the builders infallible. |
Avoids making builder methods async+fallible
GnomedDev
left a comment
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.
Looking much better, especially like the ImageData changes. Just a few more concerns though.
GnomedDev
left a comment
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.
Looking good, once someone does some testing on this I'm good with merging.
|
Tested this with message attachments and modifying a webhook's avatar, works fine in both cases. |
Implements #2690, as a second attempt at #2774. Defers reading from paths/files until the data is actually needed, which improves the performance of multipart file uploads by streaming directly from disk instead of copying into memory first. Cases where the file is included as a base64 string in the json payload are unaffected since the data needs to be encoded and written into the payload.