#!/usr/bin/perl -w
# I am having difficulty with using SOAP with MIME attachments,
# possibly due to a "binary attachment" done outside a soap
# envelope.
# Can someone tell me what I am doing wrong with this MIME::Entity ,
# so that I do not get an uncorrupted tiff or pdf file?
# The soap service is documented at http://ops.espacenet.com/ ,
# under "Input Examples" as "DocumentRetrieval"- but you probably
# do not need that, see the code below.
# Thanks.
# To run, cut and paste and s/\n\+//g
#!/usr/bin/perl -w
use SOAP::Lite ; # +trace => ['debug'] ;
use MIME::Entity;
use Data::Dumper;
my $soap = SOAP::Lite->new();
$soap-> proxy('http://ops.espacenet.com/OpenPatentServices/webService');
$soap-> ns('urn:EPO-OpenPatentServices-documentData');
$soap-> service('http://ops.espacenet.com/OpenPatentServices/webService/getPatentData?wsdl');
my $req_xml; my $som;
$req_xml = '';
#$req_xml = '';
$som = $soap->getDocumentData($req_xml);
my $mime_entity = ${$som->parts}[0];
my $body = $mime_entity->bodyhandle;
print 'mime_entity "', Dumper $mime_entity , "\"\n" ;
print 'binmode: ',$body->binmode(), ' -> ';
#$body->binmode(1);
print $body->binmode(1), "\n";
print 'is_encoded: "',$body->is_encoded(), '" -> ';
print $body->is_encoded(0), "\n";
open ( OUT , '>1.tif' ) or die "whoops $!" ;
#open ( OUT , '>1.pdf' ) or die "whoops $!" ;
print OUT $body->as_string;
close OUT;
print "Done!\n";
exit;
# typical output- and a corrupted 1.tif file.
__DATA__
mime_entity "$VAR1 = bless( {
'ME_Bodyhandle' => bless( {
'MBC_Data' => [
'binary data removed'
],
'MB_Binmode' => 1
}, 'MIME::Body::InCore' ),
'ME_Parts' => [],
'mail_inet_head' => bless( {
'mail_hdr_foldlen' => 79,
'mail_hdr_modify' => 0,
'mail_hdr_list' => [
'Content-Type: application/octet-stream
',
'Content-Transfer-Encoding: binary
',
'Content-Id:
',
'Content-Location: EP 1000000PAFP .tiff
'
],
'mail_hdr_hash' => {
'Content-Type' => [
\$VAR1->{'mail_inet_head'}{'mail_hdr_list'}[0]
],
'Content-Location' => [
\$VAR1->{'mail_inet_head'}{'mail_hdr_list'}[3]
],
'Content-Transfer-Encoding' => [
\$VAR1->{'mail_inet_head'}{'mail_hdr_list'}[1]
],
'Content-ID' => [
\$VAR1->{'mail_inet_head'}{'mail_hdr_list'}[2]
]
},
'mail_hdr_mail_from' => 'KEEP',
'mail_hdr_lengths' => {}
}, 'MIME::Head' )
}, 'MIME::Entity' );
$VAR2 = '"
';
Use of uninitialized value in print at P:/workspace/scripts/trunk/monks.pl line 36.
binmode: 1 -> 1
is_encoded: "" -> 0
Done!