簡體   English   中英

帶有Powershell腳本的Azure WebJob可將文件上傳到Azure Blob存儲

[英]Azure WebJob with Powershell Script to upload file to Azure Blob storage

我正在嘗試將Powershell腳本作為Azure Web Job(WebApp附帶的簡單腳本)運行,該腳本負責創建PDF文件並將該文件上傳到Azure Blob存儲。 成功創建文件后,使用以下命令在文件上傳期間會出現錯誤:

$pdfFileName = $reportId + ".pdf";
$storageAccountName = "MY-STORE"
$storageAccountKey = "MY-KEY"
$containerName = "_MY_CONTAINER"
$fullFileName = $PSScriptRoot + "\" + $pdfFileName

$ctx = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
Set-AzureStorageBlobContent -File "$fullFileName" -Container $containerName -Blob $pdfFileName -Context $ctx -Force

結果,我在Azure Web作業日志(在Kudu門戶中)中顯示了以下消息。

[11/15/2016 15:20:24 > 89499f: ERR ] Set-AzureStorageBlobContent : Win32 internal error "The handle is invalid" 0x6 
[11/15/2016 15:20:24 > 89499f: ERR ] occurred while reading the console output buffer. Contact Microsoft Customer 
[11/15/2016 15:20:24 > 89499f: ERR ] Support Services.
[11/15/2016 15:20:24 > 89499f: ERR ] At 
[11/15/2016 15:20:24 > 89499f: ERR ] D:\local\Temp\jobs\triggered\ddd\orgmoz1g.dqi\generateAndUploadReports.ps1:53 
[11/15/2016 15:20:24 > 89499f: ERR ] char:3
[11/15/2016 15:20:24 > 89499f: ERR ] +      Set-AzureStorageBlobContent -File $fullFileName -Container 
[11/15/2016 15:20:24 > 89499f: ERR ] $containerName -Blo ...
[11/15/2016 15:20:24 > 89499f: ERR ] +    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[11/15/2016 15:20:24 > 89499f: ERR ] ~~~~~~
[11/15/2016 15:20:24 > 89499f: ERR ]     + CategoryInfo          : ReadError: (:) [Set-AzureStorageBlobContent], Ho 
[11/15/2016 15:20:24 > 89499f: ERR ]    stException
[11/15/2016 15:20:24 > 89499f: ERR ]     + FullyQualifiedErrorId : ReadConsoleOutput,Microsoft.WindowsAzure.Command 
[11/15/2016 15:20:24 > 89499f: ERR ]    s.Storage.Blob.SetAzureBlobContentCommand

同一腳本在我的本地計算機上可以正常工作。 當我創建webjob只是為了使用Get-Module -ListAvailable列出可用模塊時, 收到了以下模塊。

    ...
[11/15/2016 15:40:36 > 89499f: INFO] ModuleType Version    Name                                ExportedCommands     
[11/15/2016 15:40:36 > 89499f: INFO] ---------- -------    ----                                ----------------     
[11/15/2016 15:40:36 > 89499f: INFO] Manifest   1.4.0      Azure                               {Get-AzureAutomati...
...
[11/15/2016 15:40:36 > 89499f: INFO] ModuleType Version    Name                                ExportedCommands     
[11/15/2016 15:40:36 > 89499f: INFO] ---------- -------    ----                                ----------------     
[11/15/2016 15:40:36 > 89499f: INFO] Manifest   1.1.2      Azure.Storage                       {Get-AzureStorageB...
...

根據您的描述,我可以重現您的問題。 經過一些試驗后,我認為這是由於PowerShell進度指示器在長時間運行的操作中在UI中提供了進度指示器。 您可以在調用Set-AzureStorageBlobContent之前通過執行以下命令來嘗試禁用Power Shell中的進度指示器:

$ProgressPreference="SilentlyContinue"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM