/**
  * Creates an UploadState object for a multipart upload by querying the
  * service for the specified upload's information.
  *
  * @param GlacierClient $client    GlacierClient object to use.
  * @param string        $vaultName Vault name for the multipart upload.
  * @param string        $uploadId  Upload ID for the multipart upload.
  * @param string        $accountId Account ID for the multipart upload.
  *
  * @return UploadState
  */
 public static function getStateFromService(GlacierClient $client, $vaultName, $uploadId, $accountId = '-')
 {
     $state = new UploadState(['accountId' => $accountId, 'vaultName' => $vaultName, 'uploadId' => $uploadId]);
     foreach ($client->getPaginator('ListParts', $state->getId()) as $result) {
         // Get the part size from the first part in the first result.
         if (!$state->getPartSize()) {
             $state->setPartSize($result['PartSizeInBytes']);
         }
         // Mark all the parts returned by ListParts as uploaded.
         foreach ($result['Parts'] as $part) {
             list($rangeIndex, $rangeSize) = self::parseRange($part['RangeInBytes'], $state->getPartSize());
             $state->markPartAsUploaded($rangeIndex, ['size' => $rangeSize, 'checksum' => $part['SHA256TreeHash']]);
         }
     }
     $state->setStatus(UploadState::INITIATED);
     return $state;
 }