Start a Conversation

This post is more than 5 years old

Solved!

Go to Solution

1622

May 9th, 2013 03:00

Atmos-php live progression of upload and download

Hello All,

 

Is there a function to call/set in Atmos-php to display live progression status of upload and download task?

This is useful to provide a visible feedback to user about their transfer condition/state.

 

Notably there are functions such as ProgressListener, SetListener, notifyProgress and have no clue how to leverage on them.

 

Is anyone implemented something similar and able to share the approach here? Appreciate that!

 

Thank you!

 

Jason Cwik 

281 Posts

May 9th, 2013 08:00

Here's a PHP sample that will print progress to the console.  Note that the first time your notifyProgress gets called the array will only contain an objectId.  On subsequent calls it will include 'currentBytes', 'totalBytes', and 'startTime'.

require_once 'EsuRestApi.php';

require_once 'EsuHelpers.php';

class ProgressPrinter implements ProgressListener {

    public function notifyProgress( array $progress, array &$results = null ) {

            if(array_key_exists("objectId", $progress)) {

                print "New object created with ID " . $progress['objectId'] . "\n";

            } else {

                print $progress['currentBytes'] . "/" . $progress['totalBytes'] . "\n";

            }

        }

  public function notifyDone( array $progress = null, array &$results = null ) {

            print "Transfer Complete.\n";

        }

  public function notifyError( array $progress = null, $exception ) {

            print "Error: " . $exception;

        }

}

$uid = 'f7412474230c40e4a293fc8aa2b0ac2e/user1';

$secret = 'K/IFTKQjLh/uAac0e14VkYueL0o=';

$host = 'your_atmos_host';

$port = 80;

$atmos = new EsuRestApi( $host, $port, $uid, $secret );

$file_to_upload = $argv[1];

$dest = new ObjectPath($argv[2]);

print "Uploading $file_to_upload to $dest\n";

$helper = new UploadHelper($atmos);

$helper->setListener(new ProgressPrinter());

$helper->createObjectFromFileOnPath($dest, $file_to_upload);

?>

Running this sample will produce output like this:

ussaaharoml1c:src cwikj$ php UploadTest.php ~/Downloads/jdk-6u38-linux-x64.bin /test1/jdk-6u38-linux-x64.bin

Uploading /Users/cwikj/Downloads/jdk-6u38-linux-x64.bin to /test1/jdk-6u38-linux-x64.bin

New object created with ID 50ef37daa3068f5a050ef505e452000518bc3c903248

0/72058033

4194304/72058033

8388608/72058033

12582912/72058033

16777216/72058033

20971520/72058033

25165824/72058033

29360128/72058033

33554432/72058033

37748736/72058033

41943040/72058033

46137344/72058033

50331648/72058033

54525952/72058033

58720256/72058033

62914560/72058033

67108864/72058033

71303168/72058033

72058033/72058033

Transfer Complete.

ussaaharoml1c:src cwikj$

14 Posts

May 9th, 2013 09:00

Thanks Jason,

Indeed this is very helpful sample code and really appreciate it!

Thanks a million!

No Events found!

Top