get_multipart_counts ( $filesize, $part_size )

Calculates the correct values for sequentially reading a file for multipart upload. This method should be used in conjunction with upload_part().

Access

public

Parameters

Parameter

Type

Required

Description

$filesize

integer

Required

The size in bytes of the entire file.

$part_size

integer

Required

The size in bytes of the part of the file to send.

Returns

Type

Description

array

An array containing key-value pairs. The keys are seekTo and length.

Examples

Get the seek position and length values for a multipart upload.

define('MB', 1048576);

// Instantiate the class
$s3 = new AmazonS3();

$response = $s3->get_multipart_counts(125*MB, 40*MB);

// Success?
var_dump($response);
Result:
array(4) {
  [0]=>
  array(2) {
    ["seekTo"]=>
    int(0)
    ["length"]=>
    int(41943040)
  }
  [1]=>
  array(2) {
    ["seekTo"]=>
    int(41943040)
    ["length"]=>
    int(41943040)
  }
  [2]=>
  array(2) {
    ["seekTo"]=>
    int(83886080)
    ["length"]=>
    int(41943040)
  }
  [3]=>
  array(2) {
    ["seekTo"]=>
    int(125829120)
    ["length"]=>
    int(5242880)
  }
}

Source

Method defined in services/s3.class.php | Toggle source view (18 lines) | View on GitHub

public function get_multipart_counts($filesize, $part_size)
{
    $i = 0;
    $sizecount = $filesize;
    $values = array();

    while ($sizecount > 0)
    {
        $sizecount -= $part_size;
        $values[] = array(
            'seekTo' => ($part_size * $i),
            'length' => (($sizecount > 0) ? $part_size : ($sizecount + $part_size)),
        );
        $i++;
    }

    return $values;
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback