I am trying to download attachments from RT 4.2.8 tickets using PHP REST API (https://github.com/dersam/RTPHPLib). I've used Ticket Attachment Content and Ticket Attachment. They return some kind of string or array like this (basically it outputs the file content):
Array
(
[%PDF-1.4
%����
] =>
[10 0 obj
<>
endobj
] =>
[15 0 obj
<>/Filter/FlateDecode/ID[<4DCDA9C01A05A34BB7A89B62345FD905><4DCDA9C01A05A34BB7A89B62345FD905>]/Index[10 7]/Info 9 0 R/Length 36/Prev 805889/Root 11 0 R/Size 17/Type/XRef/W[1 2 0]>>stream
] =>
[h�bbd`b`�db`�eb`����^��"��
] =>
[endstream
endobj
startxref
] =>
[0
] =>
[%%EOF
] =>
[16 0 obj
<>stream
] =>
[h�b```f``����33 �������L f(f`�ca```h�o�1���iF �`�] =>
[O
] =>
[endstream
endobj
11 0 obj
<>
endobj
12 0 obj
<>>>/Rotate 270/Type/Page>>
endobj
I've tried to write this with php fwrite/file_put_contents to a tmp file and then download it, but it won't open.
How can I download the ticket attachments locally? I want this to be dynamic (no matter the file extension)
For binary content, it is necessary to make an additional call to getAttachmentContent
. This will return the file contents in their original encoding.
The issue comes from RT using UTF-8 in its response, which also encodes the Content
section. Unfortunately, RT does not store the original encoding of the attachment, resulting in an unreliable Content
section, making it impossible for RTPHPLib to guess intelligently.
See https://github.com/dersam/RTPHPLib/issues/66 for some recent discussion on this.