如何使用Set-AzureStorageBlobContent

时间:2015-06-11 16:25:23

标签: powershell azure

使用Powershell(使用Azure模块),这可以:

Set-AzureStorageBlobContent -Container $containerName -Context $context -File $localfilename -Force -Properties @{ContentType='text/plain'}

这不是:

Set-AzureStorageBlobContent -Container $containerName -Context $context -File $localfilename -Force -Properties @{ContentType='text/plain';ContentDisposition='attachment; filename=foo.txt'}

我收到的错误消息说,

  

Set-AzureStorageBlobContent:Blob属性' ContentDisposition'有价值的附件;文件名= foo.txt的'无效

我做错了什么?我无法找到有关ContentDisposition属性的已接受语法的任何参考。

1 个答案:

答案 0 :(得分:3)

你没有做错任何事。我认为Azure Cmdlet中不支持ContentDisposition(但它在REST和.Net API中完全支持)。我的声明基于源代码:https://github.com/Azure/azure-powershell/blob/dev/src/ServiceManagement/Storage/Commands.Storage/Blob/Cmdlet/SetAzureStorageBlobContent.cs

来自同一页面的源代码:

    //only support the common blob properties for block blob and page blob
    //http://msdn.microsoft.com/en-us/library/windowsazure/ee691966.aspx
    private Dictionary<string, Action<StorageBlob.BlobProperties, string>> validICloudBlobProperties =
        new Dictionary<string, Action<StorageBlob.BlobProperties, string>>(StringComparer.OrdinalIgnoreCase)
        {
            {"CacheControl", (p, v) => p.CacheControl = v},
            {"ContentEncoding", (p, v) => p.ContentEncoding = v},
            {"ContentLanguage", (p, v) => p.ContentLanguage = v},
            {"ContentMD5", (p, v) => p.ContentMD5 = v},
            {"ContentType", (p, v) => p.ContentType = v},
        };

    /// <summary>
    /// check whether the blob properties is valid
    /// </summary>
    /// <param name="properties">Blob properties table</param>
    private void ValidateBlobProperties(Hashtable properties)
    {
        if (properties == null)
        {
            return;
        }

        foreach (DictionaryEntry entry in properties)
        {
            if (!validICloudBlobProperties.ContainsKey(entry.Key.ToString()))
            {
                throw new ArgumentException(String.Format(Resources.InvalidBlobProperties, entry.Key.ToString(), entry.Value.ToString()));
            }
        }
    }

如果你看到上面的代码,它会检查字典中的属性,ContentDisposition没有被定义为那里的密钥。