0

I am working on a PowerShell code that is expected to upload a JSON file to my azure Blob Storage. My PowerShell code is saved in my local drive/folder and I am running that azue PowerShell CLI. My PowerShell is falling on this command.

Set-AzStorageBlobContent -Container $containers -File "./test.json" -Context $ctx.

tried all like below Set-AzStorageBlobContent -Container $containers -File "C:/folder/test.json" -Context $ctx or Set-AzStorageBlobContent -Container $containers -File "test.json" -Context $ctx

All are falling with the below error:

Set-AzStorageBlobContent : Can not find the specified file 'C:\folder\ManJason.json'. At C:\folder\BlobUpload.ps1:23 char:5

  • Set-AzStorageBlobContent -Container $containers -File "./ManJason ...
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:) [Set-AzStorageBlobContent], ArgumentException
    • FullyQualifiedErrorId : ArgumentException,Microsoft.WindowsAzure.Commands.Storage.Blob.SetAzureBlobContentComman d

My Environment :

{ "azure-cli": "2.17.1", "azure-cli-core": "2.17.1", "azure-cli-telemetry": "1.0.6", "extensions": {} }

user1431921
  • 101
  • 1
  • 2
  • 5
  • Could you please share your PS code and path were you running your script? – Andriy Bilous Jan 14 '21 at 14:01
  • $resourceGroupName="azureiotlabs" $storageAccName="iotstorage" Connect-AzAccount Write-Host -ForegroundColor Green "Upload blob content.." $storageAcc=Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName $ctx=$storageAcc.Context $containers="blobcontainer" Set-AzStorageBlobContent -Container $containers -File 'C:\Coding Work\MyJason.json' -Context $ctx Disconnect-AzAccount – user1431921 Jan 17 '21 at 02:01

1 Answers1

0

The command in your issue is correct. But the error shows that you could not get the file from the path. Plz change it with absolute path of your local file, like C:\Users\xxx\Desktop\pic.jpg.

$account_name ="pamelastorage123"
$account_key =""      
$container="pamelac"

$context = New-AzStorageContext -StorageAccountName $account_name -StorageAccountKey $account_key    

Set-AzStorageBlobContent -Container $container -File "C:\Users\peng\Desktop\pic.jpg"  -Context $context

enter image description here


Also tried the command in your comment:

enter image description here

unknown
  • 6,778
  • 1
  • 5
  • 14