gpt4 book ai didi

具有 PowerShell、存储队列触发器和 OneDrive for Business 的 Azure Function

转载 作者:行者123 更新时间:2023-12-03 05:05:44 26 4
gpt4 key购买 nike

我正在尝试创建一个使用存储队列触发器执行 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 定义为“aapdftoimage/$file”,但它没有执行任何此类操作。

不用说,我处于停滞状态。谁能给我一些指导并纠正我的错误?

最佳答案

@Henry Hamid Safi 是正确的。使用 C#,您可以利用 Binder 对象来动态命名文件。

在您的用例中,动态提供文件名的唯一方法是将其作为触发器负载中的 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

请求正文(如果在门户中使用测试 Pane )或队列触发器负载:

{
"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)

OneDrive 文件夹屏幕截图: enter image description here

关于具有 PowerShell、存储队列触发器和 OneDrive for Business 的 Azure Function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44191163/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com