Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Need to print bucket and filename which is uploaded on S3 storage

by Athanasius (Bishop)
on Aug 21, 2019 at 07:41 UTC ( #11104773=note: print w/replies, xml ) Need Help??


in reply to Need to print bucket and filename which is uploaded on S3 storage

Hello coolsaurabh,

I’m assuming that “line 16” is this one:

my @buckets = @{$conn->buckets->{buckets} || []};

Now, the documentation for the Amazon::S3::buckets method says it “Returns undef on error, else HASHREF of results.” So you need to test for an undef return value before attempting to dereference the hash reference. For example:

my $result = $conn->buckets(); my @buckets; @buckets = @{ $result->{buckets} } if defined $result;

This way, if the call to buckets() returns undef, no dereference is attempted and @buckets remains unchanged as an empty list.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Need to print bucket and filename which is uploaded on S3 storage
by coolsaurabh (Acolyte) on Aug 21, 2019 at 07:59 UTC
    The output of this script is blank.
    #!/opt/perl/bin/perl use Amazon::S3; my $file_name = "filename.txt"; my $bucketName = "forest-upload"; my $s3 = Amazon::S3->new({ aws_access_key_id => "XX", aws_secret_access_key => "XX", retry => 1 }); my $bucket = $s3->bucket($bucketName); $bucket->add_key_filename( $file_name, $file_name, { content_type => "text/plain", } ); my $result = $s3->buckets(); my @buckets; @buckets = @{ $result->{buckets} } if defined $result;

      That means there was an error returned by Amazon.

      Have you checked the errors in $s3->err and $s3->errstr?

      Also, maybe you have not created any buckets yet?

        the script returned some HASH value when I am trying to print $s3 value.
        use Amazon::S3; my $file_name = "filename.txt"; my $bucketName = "forest-upload"; my $s3 = Amazon::S3->new({ aws_access_key_id => "XX", aws_secret_access_key => "XX", retry => 1 }); print $s3;
        Output is "Amazon::S3=HASH(0xafac08)"
      the script has no calls to "print" or "say", so why would you expect non-blank output?
Re^2: Need to print bucket and filename which is uploaded on S3 storage
by coolsaurabh (Acolyte) on Aug 21, 2019 at 07:53 UTC
    Thanks for the response. It means the script which I ran to upload the file on S3 didn't worked else it should have printed the bucket name isn't it????

      You never check the result of ->add_key_filename. Maybe that is a good point to start?

      Also, have you verified that your bucket "forest-upload" exists?

      the new script doesn't have this line, so it won't print anything:
      print $bucket->bucket . "\t" . $bucket->creation_date . "\n";
      unless i just don't understand the code at all...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2020-12-01 20:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (20 votes). Check out past polls.

    Notices?