How do I change the timeout value for Add-Blob Azure cmdlet?

南笙酒味 提交于 2019-12-11 19:05:06

问题


I'm trying to invoke Add-Blob Azure cmdlet

Add-Blob -BlobType Block -FilePath $packagePath -ContainerName $blobContainerName

and it has been working just fine until recently but now it fails with

Operation could not be completed within the specified time.

message. I suspect that for whatever reason the upload speed has got really low and so it just doesn't manage to upload the file fast enough.

Is it possible to increase the timeout value for that operation?


回答1:


Are you using the Cmdlets from http://wappowershell.codeplex.com? Please note that these cmdlets are now (kind of) deprecated and have been replaced by Windows Azure Management Cmdlets (http://msdn.microsoft.com/en-us/library/windowsazure/jj554330.aspx). Unfortunately, the cmdlet to add blob is not there in the new cmdlets.

Coming back to your question, I don't think it's possible to specify the request timeout with this Cmdlet and there's no source code available on CodePlex site for you to modify. What you could do is invoke Storage Client library directly through PowerShell. I took the liberty of modifying the code from this blog post (http://www.fsmpi.uni-bayreuth.de/~dun3/archives/uploading-a-file-to-azure-blob-storage-from-powershell/528.html) and included support for Timeout parameter there:

    Add-Type -Path "C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\2012-06\ref\Microsoft.WindowsAzure.StorageClient.dll"

    $accountName = "<your account name>";

    $accountKey = "<your account key>";

    $blobContainerName = "<your blob container name>";

    $fullFilePath = "<Full path of the file you wish to upload>";

    $requestTimeoutInSeconds = 600;

    $cloudStorageAccountNameAndKey = new-object Microsoft.WindowsAzure.StorageCredentialsAccountAndKey($accountName, $accountKey);

    $cloudStorageAccount = new-object Microsoft.WindowsAzure.CloudStorageAccount($cloudStorageAccountNameAndKey, $true);

    $cloudBlobClient = [Microsoft.WindowsAzure.StorageClient.CloudStorageAccountStorageClientExtensions]::CreateCloudBlobClient($cloudStorageAccount)

    $blobContainer = $cloudBlobClient.GetContainerReference($blobContainerName);

$blobContainer.CreateIfNotExist();

    $blockBlob = $blobContainer.GetBlockBlobReference("<blob name>");

    $blobRequestOptions = new-object Microsoft.WindowsAzure.StorageClient.BlobRequestOptions;

    $blobRequestOptions.Timeout = [TimeSpan]::FromSeconds($requestTimeoutInSeconds);

    $blockBlob.UploadFile($fullFilePath, $blobRequestOptions);

If you're looking for alternatives to Microsoft's PowerShell Cmdlets, may I suggest you take a look at Cerebrata Azure Management Cmdlets [I'm one of the devs for this product]. It has cmdlets for complete storage management and service management.

Hope this helps.



来源:https://stackoverflow.com/questions/12976896/how-do-i-change-the-timeout-value-for-add-blob-azure-cmdlet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!