/**
  * Converts filenames and file handles into EntityBody objects before the command is validated
  *
  * @param Event $event Event emitted
  * @throws InvalidArgumentException
  */
 public function onCommandBeforePrepare(Event $event)
 {
     /** @var $command Command */
     $command = $event['command'];
     if (in_array($command->getName(), $this->commands)) {
         // Get the interesting parameters
         $source = $command->get($this->sourceParameter);
         $body = $command->get($this->bodyParameter);
         // If a file path is passed in then get the file handle
         if (is_string($source) && file_exists($source)) {
             S3Signature::setFile(TRUE, $source);
             $body = fopen($source, 'r');
         }
         // Prepare the body parameter and remove the source file parameter
         if (null !== $body) {
             $command->remove($this->sourceParameter);
             $command->set($this->bodyParameter, EntityBody::factory($body));
         } else {
             throw new InvalidArgumentException("You must specify a non-null value for the {$this->bodyParameter} or {$this->sourceParameter} parameters.");
         }
     }
 }
 private function setArgs($method, $args)
 {
     S3Signature::setFile(FALSE, NULL);
     $this->dealEmptyString($args);
     if (ucfirst($method) === 'DeleteBucketWithObjects') {
         foreach ($args as $key => $value) {
             if (is_array($value) && array_key_exists('Bucket', $value)) {
                 if (array_key_exists('BucketName', $value)) {
                     unset($args[$key]['BucketName']);
                 }
                 $arg = array('BucketName' => $value['Bucket']);
                 $args[$key] = array_merge_recursive($args[$key], $arg);
             }
         }
     }
     if (ucfirst($method) === 'PutObject' || ucfirst($method) === 'UploadPart') {
         S3Signature::setFile(TRUE, NULL);
         if (array_key_exists('ContentLength', $args[0]) && array_key_exists('Body', $args[0])) {
             if (is_string($args[0]['Body']) && $args[0]['ContentLength'] > strlen($args[0]['Body'])) {
                 $args[0]['ContentLength'] = strlen($args[0]['Body']);
             }
         }
     }
     if (ucfirst($method) === 'CreateBucket' && !array_key_exists('LocationConstraint', $args[0]) && array_key_exists('region', ObsClient::$configArr)) {
         //     		array_push($args[0], ObsClient::$configArr['region']);
         $args[0]['LocationConstraint'] = ObsClient::$configArr['region'];
     }
     $this->dealEmptyString($args);
     return $args;
 }