Subject: | [BUG] BZ::Client, unable to attach zip file to a bug |
Date: | Tue, 9 May 2017 10:25:52 +0000 |
To: | "bug-BZ-Client [...] rt.cpan.org" <bug-BZ-Client [...] rt.cpan.org> |
From: | Raphael Crochet <raphael.crochet [...] actia.fr> |
Environment
This is perl 5, version 20, subversion 1 (v5.20.1) built for MSWin32-x86-multi-thread-64int
BZ::Client is up to date. (4.4001)
More than a bug, it is a lack of code.
In fact, all binary format (zip, jpg, png, ...) can't be attached to a bug thanks to BZ::Client.
We can serialize data in base64 if we encode it manually (client code), but the XMLRPC Bugzilla server is not able to recognize it as base64.
Bugzilla can't give back the original file and the result seems to be corrupted. The best that I could get is the encode base64 content, not he original file.
I tried to add the tag <base64> ...</base64> directly into data, but it can't work as data is considered ... as data and tags are escaped with <base64>.
The only solution I saw was to modify the XMLRPC client at serialization of the request (like it is already done for other data types).
I put in attachment, the module I patched to get the stuff done.
Following code snippet shows an example that works fine with patched version.
$client = BZ::Client->new( url => $url,
autologin => 0
);
sub addAttachment()
{
my ($id, $file) = @_;
open (FILE, "<",$file) or die "$0: $!";
binmode FILE;
my $data = join('', <FILE>);
close FILE;
my $file_attach=BZ::Client::XMLRPC::base64->new($data);
my $filename = basename($file); # file name
if (DEBUG) {print "AddAttachment: search for request: $id\n";}
my $bugId = getBugBySummary($id); # get bug by summary description
if (!defined $bugId) {
print "$0: Not found request for: $id \n";
die "$0: AddAttachment: Error, request $id not found to attach data!\n";
}
# hash map containing parameter of bugzilla attachment
my %params = (
ids => [ $bugId ],
file_name => $filename,
content_type => 'application/zip',
summary => $filename,
data => $file_attach,
);
my $response;
eval {
$response = $client->api_call( 'Bug.add_attachment', \%params );
print "$0: AddAttachment: $filename processed in BugZilla.\n";
};
if ($@) {
print "$0: ERROR Upload file: $@->{'message'}\n";
}
}
Regards
Raphaël CROCHET
Technology Department
Fixe : +33 (0)5 82 08 05 42
[logo_ACTIA_mail_2017]
ACTIA Automotive (siège social)
5, rue Jorge Semprun
B.P. 74215 - 31432 TOULOUSE cedex 4 (FRANCE)
http://www.actia.com<http://www.actia.com/>
[icon_mail_youtube]<http://www.youtube.com/ActiaOfficialCom> [icon_mail_linkedin] <http://www.linkedin.com/company/actia> [icon_mail_web] <http://www.actia.com/>
.............................................
Ce courrier électronique ainsi que tout fichier qui y est joint est destiné exclusivement aux personnes ou institutions dont le nom figure ci-dessus et peut contenir des informations protégées par le secret professionnel, dont la divulgation est strictement prohibée. Tout message électronique est susceptible d'altération. Actia décline toute responsabilité au titre de ce message. Le contenu de ce message ne représente en aucun cas un engagement de la part de notre société. Si vous n'êtes pas destinataire, nous vous avisons que sa lecture, sa reproduction ou sa distribution sont strictement interdites. Nous vous prions en conséquence de nous aviser immédiatement par retour de ce courrier et de supprimer ce message et tout document joint de votre société. Merci.
This email message and its enclosures is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. Any e-mail message is subject to alteration. Actia disclaims all liability in connection with this message. The content of this message does not represent any commitment from our company. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message with its enclosures. Thank you.
Message body is not shown because it is too large.
Message body is not shown because sender requested not to inline it.