mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-30 02:50:39 +00:00
Fix handling of attachments in JSON RPC (#1109)
* Fix handling of attachments in JSON RPC It turns out that using a custom serializer on an input stream did not work well. For one the stream seems to be getting closed before the JSON gets written. But also the method for writing it was throwing an UnsupportedOperationException further down in Jackson. The above simplifies the matter by simply outputting the Base64 string first and then setting it on the model. * Add missing files to attachment fix Co-authored-by: cedb <cedb@keylimebox.org>
This commit is contained in:
parent
3e60303b90
commit
35def4445d
3 changed files with 4 additions and 26 deletions
|
@ -40,12 +40,12 @@ public class GetAttachmentCommand implements JsonRpcLocalCommand {
|
|||
final var id = ns.getString("id");
|
||||
|
||||
try (InputStream attachment = m.retrieveAttachment(id)) {
|
||||
final var bytes = attachment.readAllBytes();
|
||||
final var base64 = Base64.getEncoder().encodeToString(bytes);
|
||||
if (outputWriter instanceof PlainTextWriter writer) {
|
||||
final var bytes = attachment.readAllBytes();
|
||||
final var base64 = Base64.getEncoder().encodeToString(bytes);
|
||||
writer.println(base64);
|
||||
} else if (outputWriter instanceof JsonWriter writer) {
|
||||
writer.write(new JsonAttachmentData(attachment));
|
||||
writer.write(new JsonAttachmentData(base64));
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
throw new UserErrorException("Could not find attachment with ID: " + id, ex);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue