Created
October 16, 2014 06:52
-
-
Save rposbo/2859e10bbf24ea2b689d to your computer and use it in GitHub Desktop.
A basic script to upload local files to blob storage, settings ContentType correctly for png and jpeg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param( | |
[string]$rootDir, | |
[string]$storage, | |
[string]$key, | |
[string]$container | |
) | |
try { | |
$context = New-AzureStorageContext -StorageAccountName $storage -StorageAccountKey $key | |
foreach ($file in Get-ChildItem -Path $rootDir) | |
{ | |
$prop = @{"ContentType"="application/octetstream"} | |
if ($file.Extension.ToLowerInvariant() -eq ".png") | |
{ | |
$prop = @{"ContentType"="image/png"} | |
} | |
if ($file.Extension.ToLowerInvariant() -eq ".jpg") | |
{ | |
$prop = @{"ContentType"="image/jpeg"} | |
} | |
Set-AzureStorageBlobContent -Blob $file.Name -Container $container -File $file.FullName -Context $context -Properties $prop -Force | |
} | |
} | |
catch [System.Exception] { | |
Write-Host $_.Exception.ToString() | |
exit 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment