Page 1 of 1

File Size, Date and Checksum with S3 Downloads

PostPosted: December 6th, 2011, 10:24 am
by colinp386
Hi There;

I would like to provide, file size, date and checksum of the files being downloaded from Amazon's S3 service.
How easy would that be to do with after the download had been completed or while it's in process.

Seems like this would be a nice feature to add, for those who like to check the integrity of their downloads
S3 stores this info in their store.

Many thanks.

Colin

Re: File Size, Date and Checksum with S3 Downloads

PostPosted: December 16th, 2011, 12:24 pm
by colinp386
Still looking to get an idea if this is a possibility at some point :-)

Re: File Size, Date and Checksum with S3 Downloads

PostPosted: December 18th, 2011, 3:59 pm
by Cristián Lávaque
Thanks for the suggetion, Colin. I'll forward it to the Lead Developer. :)

Re: File Size, Date and Checksum with S3 Downloads

PostPosted: December 19th, 2011, 11:50 am
by Jason Caldwell
Thanks for the heads up on this thread.

This is not something that s2Member makes possible in the current release. At some point in the future, we may release a set of developer tools to assist with this. Until then, I would recommend this PHP class, using the getObjectInfo() method. If we ever build a set of developer tools for S3, we would most likely base it on this class, which has already been well tested for some years now.

See: http://undesigned.org.za/2007/10/22/ama ... umentation
getObjectInfo: http://undesigned.org.za/2007/10/22/ama ... ObjectInfo

Re: File Size, Date and Checksum with S3 Downloads

PostPosted: December 19th, 2011, 1:21 pm
by colinp386
Thanks for the suggestion, likely I can find a way to incorporate that into my current display code, let me try. In the mean time thanks for thinking of considering incorporating into a list of dev tools

Colin

Re: File Size, Date and Checksum with S3 Downloads

PostPosted: December 30th, 2011, 1:55 am
by colinp386
Jason Caldwell wrote:Thanks for the heads up on this thread.

This is not something that s2Member makes possible in the current release. At some point in the future, we may release a set of developer tools to assist with this. Until then, I would recommend this PHP class, using the getObjectInfo() method. If we ever build a set of developer tools for S3, we would most likely base it on this class, which has already been well tested for some years now.

See: http://undesigned.org.za/2007/10/22/ama ... umentation
getObjectInfo: http://undesigned.org.za/2007/10/22/ama ... ObjectInfo


Many thanks for this Jason.
I wrote a couple of short-codes to bring back the file-size for example:
Code: Select all
/*
  Shortcode to return filesize and checksum from Amazon S3
  install S3.php class file in mu-plugin dir.
  call with [get-s3fileinfo]URI of object[/get-s3fileinfo]
*/
add_shortcode('get-s3fileinfo', 'get_s3fileinfo');
   function get_s3fileinfo($atts, $content = null){
   //include the S3 class  in case mu_plugin fails
   if (!class_exists('S3'))require_once('S3.php'); 
 
   //AWS access info 
   if (!defined('awsAccessKey')) define('awsAccessKey', 'Input access key here'); 
   if (!defined('awsSecretKey')) define('awsSecretKey', 'Input Sectret key here'); 
 
   //instantiate the class 
   $s3 = new S3(awsAccessKey, awsSecretKey); 

   $bucket = 'Bucket-Name';
   $uri = $content;
   if (($info = $s3->getObjectInfo($bucket, $uri)) !== false) {
        /*print_r($info);*/
    if (is_array ($info) && !empty ($info))
     {
       echo "Checksum: $info[hash]";
       echo "<br/>";
       echo "File size:  $info[size]";
    }
    }
}


All works well :mrgreen: other than when the filename has a + in the name.
S2member also fails, as written about in my new post. :?

Re: File Size, Date and Checksum with S3 Downloads

PostPosted: December 30th, 2011, 9:44 pm
by Jason Caldwell
Thanks for the update. Glad to hear this all worked out for you.
I see you solved the other issue with + file names as well.

I posted a quick reply in this thread, and we'll take a closer look at implementing a patch in the next release: viewtopic.php?f=4&t=16611&p=59297#p59297