Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Downloading Gmail attachments - Corrupted saved file

by localshop (Novice)
on May 13, 2013 at 23:15 UTC ( #1033376=note: print w/ replies, xml ) Need Help??


in reply to Downloading Gmail attachments - Corrupted saved file

A couple of points. If you are running on Windoze you may want to write the files in binary mode (see binmode). Also it looks to me as though you are trying to append the files instead of writing to them. Here's my code that works ok:

foreach my $at ( @attachments ) { if ( $at->{content_type} =~ /pdf/i ) { open(my $fh, '>', $at->{filename} ) || die ( $!); binmode $fh; print $fh $at->{payload}; $fh->close(); } }


Comment on Re: Downloading Gmail attachments - Corrupted saved file
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1033376]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2015-07-30 02:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls