0

I made an Azure Powershell function that needs to write some data into a blob, so am using an outputBlob binding along with:

Push-OutputBinding -Name <name> -Value <value>

That writes the data I need into the blob - great! But the issue is that every time the function runs it overwrites the blob content. I cannot see how to get the Push-OutputBinding cmdlet to append data into the blob, rather than 'set' it. I have tried setting the -Clobber switch, but it doesn't seem to make any difference.

Bindings seem like a nice way to interact with Blob storage without having to pull in more code to instantiate a more full-on client session, I hope this is possible? Would appreciate any pointers.

4 Answers 4

3

I'm reasonably confident there is no native way to append to a blob in powershell and in the output binding of an azure function, so you'd have to code for that (also, i think the only way to append to block blob is to download the content and append locally and reupload, but I'm not sure about this one).

Sign up to request clarification or add additional context in comments.

1 Comment

Understood. Thanks for clarifying.
1

As 4c74356b41 said, there is no native way to append to a blob in powershell.

But you don't need to download the content to a file locally, $storageBlob.ICloudBlob.DownloadText() can be used to download.

Following is my test code to append "123456789" to the Blob:

$connctionstring = ""
$container = ""
$blob = ""
$appendText = "123456789"

$blobContext = New-AzureStorageContext -ConnectionString $connctionstring
$storageBlob = Get-AzureStorageBlob -Blob $blob -Container $container -Context $blobContext 

$storageBlobContent = $storageBlob.ICloudBlob.DownloadText()

$storageBlobContent

$storageBlob.ICloudBlob.UploadText($storageBlobContent + $appendText)

enter image description here

3 Comments

Nice solution. Very helpful!
wdym "you don't need to download the content locally" - when you download it, lol. you dont have to save it to a file and do that in memory - sure. but you have to download it.
Yes, it will download to memory. I mean "you don't need to download the content locally" as a file. I will edit it.
0

Create an Append blob using powershell command Set-AzStorageBlobContent with blob type Append

$storageAccountName = ""
$containerName= ""
$storageContext= ""
$blobName = ""
$appendText = "123456789"

$storageContext = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $AccountKey
$patchContainer = Get-AzStorageContainer -Name $containerName -Context $storageContext
$storageBlob = Get-AzStorageBlob -Blob $blobName -Container $containerName -Context $storageContext 
$patchLogBlob = Get-AzStorageBlob -Blob $blobName -Container $containerName -Context $storageContext                         
$patchLogBlob.ICloudBlob.AppendText($appendText)

1 Comment

You mention using Set-AzStorageBlobContent in the first part of your solution, but that commandlet doesn't appear in the code sample. Is there missing code from your example?
0

It seems, there's no necessity neither to create a new StorageContext nor to Get a new storage blob, all you need to do is to get the blob object and correctly call it's interface method.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.