/** * Create a presigned URL with a command object that has x-amz-* headers. * * @depends testGetObjectWithSaveAs */ public function testCreatePresignedUrlWithAcl() { $this->client->waitUntil('BucketExists', array('Bucket' => $this->bucket)); $client = $this->client; $bucket = $this->bucket; $command = $client->getCommand('PutObject', array('Bucket' => $bucket, 'Key' => 'preput', 'ACL' => 'public-read', 'Content-Type' => 'plain/text', 'Body' => '')); $signedUrl = $command->createPresignedUrl('+10 minutes'); $ch = curl_init($signedUrl); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: plain/text')); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_POSTFIELDS, 'abc123'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_exec($ch); }
/** * @depends testPutAndListObjects */ public function testPreSignedUrlAllowsSpecialCharacters() { self::log('Uploading an object with a space in the key'); $this->client->waitUntil('bucket_exists', array('Bucket' => $this->bucket)); $key = 'foo baz bar!'; $this->client->putObject(array('Bucket' => $this->bucket, 'Key' => $key, 'Body' => 'hi')); $this->client->waitUntil('object_exists', array('Bucket' => $this->bucket, 'Key' => $key)); self::log('Creating an downloading using a pre-signed URL with command'); $command = $this->client->getCommand('GetObject', array('Bucket' => $this->bucket, 'Key' => $key)); $url = $command->createPresignedUrl('+100 minutes'); self::log($url); $this->assertEquals('hi', file_get_contents($url)); self::log('Creating an downloading using a pre-signed URL'); $extra = urlencode("attachment; filename=\"{$key}\""); $request = $this->client->get("{$this->bucket}/{$key}?response-content-disposition={$extra}"); $url = $this->client->createPresignedUrl($request, '+10 minutes'); self::log($url); $client = new Client(); $this->assertEquals('hi', file_get_contents($url)); $this->assertEquals('hi', $client->get($url)->send()->getBody(true)); }