public function testCanSetAcpOnMultipartUploadsAndEmitsDebug()
 {
     $client = $this->getServiceBuilder()->get('s3', true);
     $this->setMockResponse($client, array('s3/list_objects_empty', 's3/initiate_multipart_upload', 's3/upload_part', 's3/complete_multipart_upload'));
     $out = fopen('php://temp', 'r+');
     UploadSyncBuilder::getInstance()->setBucket('foo')->setClient($client)->setBaseDir(__DIR__)->enableDebugOutput($out)->setSourceIterator(new \ArrayIterator(array(new \SplFileInfo(__FILE__))))->setMultipartUploadSize(filesize(__FILE__) - 1)->setAcp(AcpBuilder::newInstance()->setOwner('123')->addGrantForEmail('READ_ACP', '*****@*****.**')->build())->build()->transfer();
     $requests = $this->getMockedRequests();
     $this->assertCount(4, $requests);
     $this->assertEquals('POST', $requests[1]->getMethod());
     $this->assertContains('?uploads', $requests[1]->getResource());
     $this->assertNotNull($requests[1]->getHeader('x-amz-grant-read-acp'));
     $this->assertEquals('PUT', $requests[2]->getMethod());
     $this->assertEquals('POST', $requests[3]->getMethod());
     $this->assertContains('uploadId=', $requests[3]->getResource());
     rewind($out);
     $contents = stream_get_contents($out);
     $this->assertContains('Beginning multipart upload: ' . __FILE__ . ' -> UploadSyncBuilderTest.php (', $contents);
     $this->assertContains('- Part 1 (', $contents);
 }
Пример #2
0
 public function register(Carew $carew)
 {
     $container = $carew->getContainer();
     if (!array_key_exists('aws', $container['config'])) {
         throw new \LogicException('The key "aws" does not exist in the config.yml file');
     }
     $awsConf = $container['config']['aws'];
     foreach (array('bucket', 'key', 'secret') as $key) {
         if (!array_key_exists($key, $awsConf)) {
             throw new \LogicException(sprintf('The key "%s" does not exist in the config.yml file', $key));
         }
     }
     $carew->register('deploy')->setDescription('Deploy the website')->setCode(function (InputInterface $input, OutputInterface $output) use($awsConf) {
         $client = S3Client::factory(array('key' => $awsConf['key'], 'secret' => $awsConf['secret']));
         $webDir = sprintf('%s/web', $input->getOption('base-dir'));
         if (!is_dir($webDir)) {
             throw new \InvalidArgumentException(sprintf('The web directory "%s" does not exist.', $webDir));
         }
         UploadSyncBuilder::getInstance()->setClient($client)->setBucket($awsConf['bucket'])->enableDebugOutput()->setAcl('public-read')->uploadFromDirectory($webDir)->build()->transfer();
     });
 }
Пример #3
0
 /**
  * Recursively uploads all files in a given directory to a given bucket.
  *
  * @param string $directory Full path to a directory to upload
  * @param string $bucket    Name of the bucket
  * @param string $keyPrefix Virtual directory key prefix to add to each upload
  * @param array  $options   Associative array of upload options
  *     - params: Array of parameters to use with each PutObject operation performed during the transfer
  *     - base_dir: Base directory to remove from each object key
  *     - force: Set to true to upload every file, even if the file is already in Amazon S3 and has not changed
  *     - concurrency: Maximum number of parallel uploads (defaults to 10)
  *     - debug: Set to true or an fopen resource to enable debug mode to print information about each upload
  *     - multipart_upload_size: When the size of a file exceeds this value, the file will be uploaded using a
  *       multipart upload.
  *
  * @see Aws\S3\S3Sync\S3Sync for more options and customization
  */
 public function uploadDirectory($directory, $bucket, $keyPrefix = null, array $options = array())
 {
     $options = Collection::fromConfig($options, array('base_dir' => $directory));
     $builder = $options['builder'] ?: UploadSyncBuilder::getInstance();
     $builder->uploadFromDirectory($directory)->setClient($this)->setBucket($bucket)->setKeyPrefix($keyPrefix)->setConcurrency($options['concurrency'] ?: 5)->setBaseDir($options['base_dir'])->force($options['force'])->setOperationParams($options['params'] ?: array())->enableDebugOutput($options['debug']);
     if ($options->hasKey('multipart_upload_size')) {
         $builder->setMultipartUploadSize($options['multipart_upload_size']);
     }
     $builder->build()->transfer();
 }