Permalink
Browse files

下載 Blob

  • Loading branch information...
1 parent fe083b5 commit ee55a135ee2ec1b0e319707674c8f2cf79893790 Sam.IO.Hsiao committed Aug 14, 2016
Showing with 22 additions and 0 deletions.
  1. +22 −0 app/Services/AzureBlobService.php
@@ -5,6 +5,7 @@
use Illuminate\Support\Collection;
use MicrosoftAzure\Storage\Blob\Internal\IBlob;
use MicrosoftAzure\Storage\Blob\Models\Blob;
+use MicrosoftAzure\Storage\Blob\Models\GetBlobResult;
use MicrosoftAzure\Storage\Blob\Models\ListBlobsResult;
use MicrosoftAzure\Storage\Common\ServiceException;
use WindowsAzure\Common\ServicesBuilder;
@@ -83,4 +84,25 @@ public function listAllBlobs(string $containerName) : Collection
return collect([]);
}
}
+
+ /**
+ * 下載 Blob
+ * @param string $containerName
+ * @param string $blobName
+ * @return bool
+ */
+ public function downloadBlob(string $containerName, string $blobName) : bool
+ {
+ try {
+ /** @var GetBlobResult $blob */
+ $blob = $this->blobProxy->getBlob($containerName, $blobName);
+ fpassthru($blob->getContentStream());
+ } catch (ServiceException $exception) {
+ echo $exception->getCode() . ':' . $exception->getMessage();
+ return false;
+ }
+
+ return true;
+ }
+
}

0 comments on commit ee55a13

Please sign in to comment.