Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from john-dent/master
Browse files Browse the repository at this point in the history
Updated getUrl() to handle azure $root container
  • Loading branch information
matthewbdaly committed Jul 14, 2019
2 parents 2519cf6 + b1ecf97 commit 81de7ba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -26,10 +26,11 @@ Then add this to the `disks` section of `config/filesystems.php`:
'name' => env('AZURE_STORAGE_NAME'),
'key' => env('AZURE_STORAGE_KEY'),
'container' => env('AZURE_STORAGE_CONTAINER'),
'url' => env('AZURE_STORAGE_URL'),
],
```

Finally, add the fields `AZURE_STORAGE_NAME`, `AZURE_STORAGE_KEY` and `AZURE_STORAGE_CONTAINER` to your `.env` file with the appropriate credentials. Then you can set the `azure` driver as either your default or cloud driver and use it to fetch and retrieve files as usual.
Finally, add the fields `AZURE_STORAGE_NAME`, `AZURE_STORAGE_KEY`, `AZURE_STORAGE_CONTAINER` and `AZURE_STORAGE_URL` to your `.env` file with the appropriate credentials. The `AZURE_STORAGE_URL` field is optional, this allows you to set a custom URL to be returned from `Storage::url()`, if using the `$root` continer the URL will be returned without the container path. Then you can set the `azure` driver as either your default or cloud driver and use it to fetch and retrieve files as usual.

# Support policy

Expand Down
2 changes: 1 addition & 1 deletion src/AzureBlobStorageAdapter.php
Expand Up @@ -62,7 +62,7 @@ public function __construct(BlobRestProxy $client, string $container, string $ur
public function getUrl(string $path)
{
if ($this->url) {
return rtrim($this->url, '/') . '/' . $this->container . '/' . ltrim($path, '/');
return rtrim($this->url, '/') . '/' . ($this->container === '$root' ? '' : $this->container . '/') . ltrim($path, '/');
}
return $this->client->getBlobUrl($this->container, $path);
}
Expand Down
9 changes: 9 additions & 0 deletions tests/AzureBlobStorageAdapterTest.php
Expand Up @@ -42,6 +42,15 @@ public function it_supports_custom_url()
$this->assertEquals('https://example.com/azure_container/test.txt', $adapter->getUrl('test.txt'));
}

/** @test */
public function it_supports_custom_url_with_root_container()
{
$client = BlobRestProxy::createBlobService('DefaultEndpointsProtocol=https;AccountName=azure_account;AccountKey=' . base64_encode('azure_key'));
$adapter = new AzureBlobStorageAdapter($client, '$root', 'https://example.com');

$this->assertEquals('https://example.com/test.txt', $adapter->getUrl('test.txt'));
}

/** @test */
public function it_handles_invalid_custom_url()
{
Expand Down

0 comments on commit 81de7ba

Please sign in to comment.