Permalink
Browse files

顯示所有 Blob

  • Loading branch information...
1 parent 43cf305 commit ec3b356bc8f55d5b1a8bf0b2d25f667aa126b257 Sam.IO.Hsiao committed Aug 14, 2016
Showing with 26 additions and 0 deletions.
  1. +26 −0 app/Services/AzureBlobService.php
@@ -2,7 +2,10 @@
namespace App\Services;
+use Illuminate\Support\Collection;
use MicrosoftAzure\Storage\Blob\Internal\IBlob;
+use MicrosoftAzure\Storage\Blob\Models\Blob;
+use MicrosoftAzure\Storage\Blob\Models\ListBlobsResult;
use MicrosoftAzure\Storage\Common\ServiceException;
use WindowsAzure\Common\ServicesBuilder;
@@ -57,4 +60,27 @@ public function createBlob(string $containerName, string $blobName, $content) :
return true;
}
+
+ /** 列出 Container 的所有 Blob
+ * @param string $containerName
+ * @return Collection
+ */
+ public function listAllBlobs(string $containerName) : Collection
+ {
+ try {
+ /** @var ListBlobsResult $blobLists */
+ $blobLists = $this->blobProxy->listBlobs($containerName);
+ $blobs = $blobLists->getBlobs();
+
+ return collect($blobs)->map(function (Blob $blob) {
+ return [
+ 'name' => $blob->getName(),
+ 'url' => $blob->getUrl(),
+ ];
+ });
+ } catch (ServiceException $exception) {
+ echo $exception->getCode() . ':' . $exception->getMessage();
+ return collect([]);
+ }
+ }
}

0 comments on commit ec3b356

Please sign in to comment.