locked
Setting Azure Blob Content Type in Powershell RRS feed

  • Question

  • Hi,

    I'm using Set-AzureStorageBlobContent to upload a bunch of files to an azure storage container from a powershell script. The ContentType is loaded as "application/octet-stream", which I believe is the default, but I want to set it as "image/jpeg" to match the type of files that I'm uploading. How can I do this? I tried (intuitively) using -ContentType on the command, but this is unrecognised.

    Yours, in frustration

      

    • Moved by Bill_Stewart Monday, February 3, 2014 3:24 PM Move to more appropriate forum
    Monday, February 3, 2014 1:04 PM

Answers

  • Looking at the documentation here: http://msdn.microsoft.com/en-us/library/dn495279.aspx, you would need to specify properties in a HashTable. Please see PowerShell code snippet to upload a png file using this cmdlet:

    $accountName = "accountname"
    $accountKey = "accountkey"
    $context = New-AzureStorageContext -StorageAccountName $accountName -StorageAccountKey $accountKey
    $containerName = "containername"
    $blobProperties = @{"ContentType" = "image/png"};
    Set-AzureStorageBlobContent -File "D:\tSmile.png" -Container $containerName -BlobType "Block" -Properties $blobProperties -Context $context
    
    Hope this helps.

    @jrv --> I don't think that's correct. Some browsers actually go by the content-type property. For example, let's say you upload a png file and set its content type to "application/octet-stream". Now when you access this blob  in IE, it would display it correctly in the browser. However if you access the same blob in Chrome, it will prompt you to download the file.

    Thursday, February 6, 2014 3:26 PM

All replies

  • Hi,

    I'm using Set-AzureStorageBlobContent to upload a bunch of files to an azure storage container from a powershell script. The ContentType is loaded as "application/octet-stream", which I believe is the default, but I want to set it as "image/jpeg" to match the type of files that I'm uploading. How can I do this? I tried (intuitively) using -ContentType on the command, but this is unrecognised.

    Yours, in frustration

      

    octet-stream should upload an type of file. Files are recognized by their content and extension. jpeg is an octet stream.

    Azure stores binary data and no files.


    ¯\_(ツ)_/¯

    Monday, February 3, 2014 3:46 PM
  • Looking at the documentation here: http://msdn.microsoft.com/en-us/library/dn495279.aspx, you would need to specify properties in a HashTable. Please see PowerShell code snippet to upload a png file using this cmdlet:

    $accountName = "accountname"
    $accountKey = "accountkey"
    $context = New-AzureStorageContext -StorageAccountName $accountName -StorageAccountKey $accountKey
    $containerName = "containername"
    $blobProperties = @{"ContentType" = "image/png"};
    Set-AzureStorageBlobContent -File "D:\tSmile.png" -Container $containerName -BlobType "Block" -Properties $blobProperties -Context $context
    
    Hope this helps.

    @jrv --> I don't think that's correct. Some browsers actually go by the content-type property. For example, let's say you upload a png file and set its content type to "application/octet-stream". Now when you access this blob  in IE, it would display it correctly in the browser. However if you access the same blob in Chrome, it will prompt you to download the file.

    Thursday, February 6, 2014 3:26 PM
  • Guarav.  I though of that.  I am not sure that the content type is set that way.  In most web servers the content type is defined by the extension.  The server just want to know how to store the file and a blob is a binary.  The binary has an internal type and an extension to identify it to a browser.

    I could be wrong about this but this is the way MSSQLServer works and SharePoint is MSSQLServer.

    I am interested to see if your method does work.


    ¯\_(ツ)_/¯

    Thursday, February 6, 2014 3:31 PM
  • My comments were solely based on my experience with blob storage so I may be wrong in generalizing it but as far as blob storage goes, I think because is it simply a storage service it does not have the intelligence of a web server. It would take whatever you specify and if you don't specify anything it just picks the default which is application/octet-stream. I have seen a number of threads here where because of incorrect content type, the image or document is not displayed.

    Thursday, February 6, 2014 3:35 PM
  • It makes sense.  I will try it later.

    ¯\_(ツ)_/¯

    Thursday, February 6, 2014 3:42 PM