Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

problems with decoding by using base64 method

by anil1.perl (Initiate)
on Aug 03, 2016 at 10:44 UTC ( [id://1169074]=perlquestion: print w/replies, xml ) Need Help??

anil1.perl has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am facing problems while decoding , we are using base64 decoding method. We are decoding thousands of files, when we open those files some of them are opened properly and some of them are giving error message saying "FIle is corrupted". We are not understanding why some of the files are not opening after the decode, what we observed is, the files which are having scanned images, files with screen shots, the files with headers & footers are not opening after decoding. Any help is really appreciated. Thanks !! Regards, Anil
  • Comment on problems with decoding by using base64 method

Replies are listed 'Best First'.
Re: problems with decoding by using base64 method
by choroba (Cardinal) on Aug 03, 2016 at 10:57 UTC
    Hi anil1.perl, welcome to the Monastery!

    Without seeing the code that produced the files and tries to decode them back, we can't help you much. Sounds like a missing binmode somewhere.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      Thanks for your reply.

      Actually we have legacy PERL application which encodes(using base64) the file content and puts data into the DB.

      Now we have written a script to download & decode those attachment from that DB.

      Below is the code we are using for this:

        That was tough to wade through, you should put code in-between <code>...</code> tags. But basically, I see this

        my $filePath1 = "/tools/busapps/LAMP/dev/APP/htdocs/APP/APP_Attachment +s/2016/LGop.pdf"; open (my $upload_filehandle,'<',$filePath1); binmode $upload_filehandle; my $filecontents; { local $/ = undef; $filecontents = <$upload_filehandle>; } my $fContent = decode_base64( $filecontents );
        and unless your file naming conventions are strange, a pdf file is not base64 encoded.

        What you need to do is first identify and isolate a file that is failing to decode. Move it off to the side and then write a very small script that just opens that problem file and tries to decode_base64 it. More than likely, you'll find the problem is with the actual file (it's not base64 encoded) and not the decode_base64 routine.

        -derby
        If this is running under Windows, extra bytes are probably being added when you write your decoded binary data from the $fContent variable to OFILE. If this is the case, you could fix it by adding the line binmode OFILE; immediately after lines which begin with open ( OFILE,...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1169074]
Approved by choroba
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-19 13:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found