sachinhere has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I have base64 pdf data that stored in database. The code that I am trying to write is
to decode the base64 data from database write it into file with .pdf extension upload that file
on amazon S3 and generate URL for pdf file. Everything seems fine but while hitting generated URL
on browser I am getting an error "Failed to load PDF document".I am using Amazon::S3 and Muck::FS::S3::QueryStringAuthGenerator
cpan modules for amazon upload and MIME::Base64 for decoding Base64 pdf data.
below is the code snippet:

my $s3 = Amazon::S3->new ( { aws_access_key_id => $aws_Access_key_id, aws_secret_access_key => $aws_secret_access_key } ); my $test_bucket = $s3->bucket("testbucket"); my $uploadFile_keyname = "r3u3298982938"; my $add_file_test = $test_bucket->add_key_filename("$uploadF +ile_keyname","$cUpload_file",{content_type=>'application/pdf'}) or die "Couldn't copy file to bucket" .$s3->errstr ."\n"; my $response = $test_bucket->list; for my $key(@{ $response->{keys}}) { if($key->{key} eq "$uploadFile_keyname") { my $urlenerator = Muck::FS::S3::QueryStringAuthGenerat +or->new($aws_Access_key_id,$aws_secret_access_key); $urlenerator->expires_in(36000000); $url = $urlenerator->get('testbucket',"$uploadFile_key +name"); } } return $url;

Replies are listed 'Best First'.
Re: Upload to AWS S3 bucket
by hippo (Archbishop) on Jan 17, 2018 at 09:08 UTC
    Everything seems fine but while hitting generated URL on browser I am getting an error "Failed to load PDF document".

    Which browser? That's not an overly helpful error message but reading between the lines it sounds like it is retrieving the file OK but that the browser's internal PDF viewer cannot display it. I would attempt to retrieve the file in some reliable way from S3 (eg. with lwp-download) and then examine the downloaded file to see if it is corrupt or otherwise invalid as a PDF.

      Well I am trying to open in chrome browser but looks like its something related to decoding of the document. I have tried to download via wget and its showing the same error.