我尝试使用存储队列触发器创建执行PowerShell的Azure功能。出于测试目的,我希望此功能可以操作OneDrive for Business帐户中的文件。要将文件从aapdftoimage/ThreePages.pdf
复制到aapdftoimage/output_ThreePages.pdf
。
当OneDrive for Business集成为输入时,只要队列中的新消息触发该功能,我就会收到错误。如果我断开OneDrive作为输入,我不会收到任何错误,$triggerInput
包含该消息。
错误是:
2017-05-25T22:24:38.484 Function started (Id=a0c37fdf-ed3c-473c-9c79-236d63531e7e)
2017-05-25T22:24:38.499 Function completed (Failure, Id=a0c37fdf-ed3c-473c-9c79-236d63531e7e, Duration=1ms)
2017-05-25T22:24:38.562 Exception while executing function: Functions.QueueTriggerPowerShell1. Microsoft.Azure.WebJobs.Host: No value for named parameter 'file'.
这是我的PowerShell:
$inData = Get-Content $triggerInput
$inFile = Get-Content $inputFile
Write-Output "PowerShell script processed queue message '$inData'"
Write-Output "inFile: $inFile"
这里有function.json:
{
"bindings": [
{
"name": "triggerInput",
"type": "queueTrigger",
"direction": "in",
"queueName": "samples-powershell-pdftoimage",
"connection": "<storageaccount>_STORAGE"
},
{
"type": "apiHubFile",
"name": "inputFile",
"path": "aapdftoimage/{file}",
"connection": "onedriveforbusiness1_ONEDRIVEFORBUSINESS",
"direction": "in"
}
],
"disabled": false
}
在我写这篇文章时,我认为我的一部分困惑在于OneDrive for Business的输入和输出(在我的测试中没有连接)。
我知道$triggerInput
是什么。它是消息的内容。但是什么是$inputFile
? {file}
来自哪里?
我想也许我会做以下但是它也不起作用(相同的错误):
$file = Get-Content $triggerInput
我认为这可能会将$inputFile
定义为&#34; aapdftoimage / $ file&#34;但它什么都不做。
毋庸置疑,我处于停滞状态。任何人都可以给我一些指导并理顺我吗?
答案 0 :(得分:2)
在您的用例中,动态提供文件名的唯一方法是将其作为触发器有效内容中的JSON对象传递。这是一个适合我的示例设置。
<强> function.json:强>
{
"bindings": [
{
"name": "triggerInput",
"type": "queueTrigger",
"direction": "in",
"queueName": "samples-powershell",
"connection": "AzureWebJobsStorage"
},
{
"type": "apiHubFile",
"name": "inputFile",
"path": "aapdftoimage/{file}",
"connection": "onedriveforbusiness_ONEDRIVEFORBUSINESS",
"direction": "in"
},
{
"type": "apiHubFile",
"name": "outputFile",
"path": "aapdftoimage/output_{file}",
"connection": "onedriveforbusiness_ONEDRIVEFORBUSINESS",
"direction": "out"
}
],
"disabled": false
}
<强> run.ps1:强>
$in = Get-Content $triggerInput
Write-Output "PowerShell script processed queue message '$in'"
Copy-Item $inputFile $outputFile
请求正文(如果在Portal中使用测试窗格)或队列触发器有效负载:
{
"file":"ThreePages.pdf"
}
记录条目:
2017-05-26T22:27:53.984 Function started (Id=032c4469-8378-44ce-af9e-5a941afb0d82)
2017-05-26T22:27:54.875 PowerShell script processed queue message '{ "file":"ThreePages.pdf" }'
2017-05-26T22:27:54.891 Function completed (Success, Id=032c4469-8378-44ce-af9e-5a941afb0d82, Duration=899ms)
答案 1 :(得分:1)
工作示例
Function.json:
{
"bindings": [
{
"name": "triggerInput",
"type": "queueTrigger",
"direction": "in",
"queueName": "test",
"connection": "AzureWebJobsDashboard"
},
{
"type": "apiHubFile",
"name": "inputFile",
"path": "aapdftoimage/ThreePages.pdf",
"connection": "onedrive_ONEDRIVE",
"direction": "in"
},
{
"type": "apiHubFile",
"name": "outputFile",
"path": "aapdftoimage/output_ThreePages.pdf",
"connection": "onedrive_ONEDRIVE",
"direction": "out"
}
],
"disabled": false
}
run.ps1:
$in = Get-Content $triggerInput
Write-Output "PowerShell script processed queue message '$in'"
Copy-Item $inputFile $outputFile