Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Azure storage blob url after uploading powershell

How can i get url of the blob i just uploaded using powershell.My code currently is

$storagekey=Get-AzureStorageKey -StorageAccountName appstorageacc
$ctx=New-AzureStorageContext -StorageAccountName 
appstorageacc -   StorageAccountKey $storagekey.Primary
Set-AzureStorageBlobContent -File C:\Package\StarterSite.zip 
-Container   clouddata -Context $ctx -Force

Blob is uploaded successfully, but how can i get it's url out?

like image 551
Mandar Jogalekar Avatar asked Nov 12 '15 09:11

Mandar Jogalekar


People also ask

How do I get Azure blob storage URL?

One way to find the URL of the blob is by using the Azure portal by going to Home > Storage Account > Container > Blob > Properties. However, probably the easiest way is to find the blob in the Storage Explorer, right-click, then select 'Copy URL'. This will copy the resource URL directly to the clipboard.

How do I know if my Azure blob storage upload was successful?

Is there any way to check the status of a blob upload? If no exception throws from your code, it means the blob has been uploaded successfully. Otherwise, a exception will be thrown. You can also confirm it using any web debugging proxy tool(ex.

How do I download an Azure blob storage file by URL?

In order to download an Azure BLOB Storage item by its URL, you need to instantiate a CloudBlockBlob yourself using the item's URL: var blob = new CloudBlockBlob(new Uri(pdfFileUrl), cloudStorageAccount. Credentials); This blob can then be downloaded with the code you originally posted.


2 Answers

Retrieve blob information using the Get-AzureStorageBlob cmdlet and select the AbsoluteUri:

(Get-AzureStorageBlob -blob 'StarterSite.zip' -Container 'clouddata ').ICloudBlob.uri.AbsoluteUri
like image 74
Martin Brandl Avatar answered Jan 02 '23 07:01

Martin Brandl


Another option: just capture the result of Set-AzureStorageBlobContent

$result = Set-AzureStorageBlobContent -File C:\Package\StarterSite.zip
$blobUri = $result.ICloudBlob.Uri.AbsoluteUri

It's not necessary to call Get-AzureStorageBlob after calling Set-AzureStorageBlobContent.

Set-AzureStorageBlobContent returns the same object type that Get-AzureStorageBlob returns.

More details

The output type is AzureStorageBlob for both Get-AzureStorageBlob and Set-AzureStorageBlobContent

AzureStorageBlob has a ICloudBlob property

AzureStorageBlob.ICloudBlob getter returns a CloudBlob which has the Uri property

like image 41
egnomerator Avatar answered Jan 02 '23 07:01

egnomerator