Subject: | Problems downloading attachments |
Date: | Wed, 3 Oct 2018 18:07:57 +0100 |
To: | bug-RT-Client-REST [...] rt.cpan.org |
From: | Martin Ward <wardmw [...] gmail.com> |
Hi all,
I am trying to write a Perl script that downloads file attachments from an old RT instance that needs to be decommissioned. The problem is that the RT modules seem to be doing something to the binary code such that the size is incorrect.
When I download the attachment via the website it transfer fine. The example I man using is a zip file and I can unzip it fine afterwards; the file size is 460,749 bytes.
If I retrieve the attachment by retrieving the ticket and iterating through the attachments then the size of the content file is 442,958 bytes, so bigger than expected. If I simply save this file then it is unreadable.
I have tried encode_base64, decode_base64, encode_utf8 and decode_utf8 functions to en-decode the string to try and get it in to a reasonable state ( 460,749 bytes long and readable as a .zip file) but to no avail.
I believe that it might be something to do with wide characters because if I do a hex dump of the start of the downloaded file I get:
0000000 50 4b 03 04 14 00 09 00 - 08 00 67 8d 25 46 00 00
0000010 00 00 00 00 00 00 00 00 - 00 00 1c 00 00 00 73 63
0000020 72 65 65 6e 73 68 6f 74 - 2d 31 37 32 20 32 31 20
0000030 32 34 32 20 36 34 2e 7a - 69 70 32 9e 8a fc b5 15
but if I hex dump the first few parts of the content I retrieve from RT then I get:
00000000 50 4B 03 04 14 00 09 00 - 08 00 67 FFFD 25 46 00 00
00000010 00 00 00 00 00 00 00 00 - 00 00 1C 00 00 00 73 63
00000020 72 65 65 6E 73 68 6F 74 - 2D 31 37 32 20 32 31 20
00000030 32 34 32 20 36 34 2E 7A - 69 70 32 FFFD FFFD FFFD FFFD 15
As you can see, there are a few wide characters in the attachment and I cannot explain their being there.
I would appreciate any thoughts you have on this. The code I used to generate the hex dump is:
#!/usr/bin/env perl
#
# wctest.pl - A test to see where the wide characters come from.
use strict;
use warnings;
use RT::Client::REST;
use RT::Client::REST::Ticket;
use Data::HexDump;
my $user='user';
my $pass='pass';
my $rt = RT::Client::REST->new(
server => ('https://rt.local'),
basic_auth_cb => ( sub { return ($user, $pass); } )
);
$rt->login( username=> $user, password=> $pass,);
my $ticket_ptr = RT::Client::REST::Ticket->new(rt => $rt);
my $results = $ticket_ptr->search( limits => [ { attribute => 'id', operator => '=', value => '51447' }, ],);
my $iterator = $results->get_iterator;
my ($ticket, $attachments);
while ($ticket = &$iterator) {
$attachments = $ticket->attachments;
# Store attachments
my $atch_ater = $attachments->get_iterator;
while (my $att = &$atch_ater) {
next if ($att->file_name eq '');
print HexDump substr($att->content, 0, 64);
}
}
My environment is:
RT instance: 4.0.23
Perl:5.16.3
RT Perl libraries: 0.52
O/S: inux rt50778.a.nominum.com 2.6.32-431.el6.x86_64
. |\/|artin