简体   繁体   English

带有Powershell脚本的Azure WebJob可将文件上传到Azure Blob存储

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

I am trying to run powershell script as Azure Web Job (simple one that comes with WebApps) that is responsible for creating PDF file and uploading that file to Azure Blob Storage. 我正在尝试将Powershell脚本作为Azure Web Job(WebApp附带的简单脚本)运行,该脚本负责创建PDF文件并将该文件上传到Azure Blob存储。 When file is successfully created there is an error during file upload using following commands: 成功创建文件后,使用以下命令在文件上传期间会出现错误:

$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

As a result I have following message that is displayed in Azure Web Jobs logs (in Kudu portal). 结果,我在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

Same script works correctly on my local machine. 同一脚本在我的本地计算机上可以正常工作。 What is more when I created webjob just to list available modules using Get-Module -ListAvailable i received modules with following ones as well. 当我创建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...
...

According to your description, I could reproduce your issue. 根据您的描述,我可以重现您的问题。 After some trials, I assumed that it was due to PowerShell Progress Indicators which provides progress indicators in the UI during long-running operations. 经过一些试验后,我认为这是由于PowerShell进度指示器在长时间运行的操作中在UI中提供了进度指示器。 You could try to disable progress indicators in Power Shell by executing the following command before you call Set-AzureStorageBlobContent : 您可以在调用Set-AzureStorageBlobContent之前通过执行以下命令来尝试禁用Power Shell中的进度指示器:

$ProgressPreference="SilentlyContinue"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Azure 模块在 PowerShell 中使用 Azure 函数将文件上传到 blob 存储 - upload file to blob storage with Azure functions in PowerShell using Azure module 使用 PowerShell 脚本从 Azure Blob 存储读取 JSON 文件并写回 Blob 存储中的另一个文件 - Read JSON file from Azure Blob Storage using PowerShell script and write back to another file in blob storage powershell 上传blob到azure blob存储集内容类型 - powershell upload blob to azure blob storage set content type 将CSV文件上传到Azure BLOB存储 - Upload csv file to Azure BLOB Storage Powershell Azure Function 将 Excel 文件写入 Azure Blob 存储 - Powershell Azure Function to write an Excel file to Azure Blob Storage 如何在 PowerShell 中将缓冲区直接上传到 Azure 存储 Blob? - How do I upload a buffer directly to a Azure storage blob in PowerShell? Azure Powershell-如何使用“仅写”共享访问签名(SAS)将文件上传到Blob存储? - Azure Powershell - How to upload file to Blob Storage using “write-only” shared access signature (SAS)? 写入 Azure 存储 Blob (PowerShell) - Write to Azure Storage Blob (PowerShell) 无法将Powershell 5.0脚本作为Azure Webjob执行 - Can not execute powershell 5.0 script as azure webjob 运行涉及AzureRM作为Azure Webjob的Powershell脚本 - Running a powershell script involving AzureRM as an Azure webjob
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM