【发布时间】:2019-09-06 16:29:32
【问题描述】:
是否可以在 Powershell Core Azure Function 中创建和写入本地文件?
这是我正在运行的脚本的摘录(使用 blob 存储触发器)。
param([byte[]] $dockerFile, $TriggerMetadata)
Write-Host "Processing updated DockerFile: $($TriggerMetadata.dockerFile)"
Write-Host "---------------------------------------------------------"
Write-Host "Create local Docker File using contents from blob storage"
New-Item -Name $TriggerMetadata.snapshotId -ItemType "file"
[io.file]::WriteAllBytes($TriggerMetadata.snapshotId, $dockerFile)
Get-Content $TriggerMetadata.snapshotId
Write-Host "---------------------------------------------------------"
使用New-Item 会抛出这个 ->
ERROR: Could not find file 'D:\home\site\wwwroot\<filename>'.
而使用 [io.file]::WriteAllBytes 会抛出这个 -> Exception calling "WriteAllBytes" with "2" argument(s): "Could not find file 'D:\home\site\wwwroot\<filename>'."
Azure Functions 是否有权在本地创建文件?
【问题讨论】:
-
您可以尝试获取临时文件夹并在那里写入吗? stackoverflow.com/a/34559554/1537195
$parent = [System.IO.Path]::GetTempPath() -
@silent 这确实有效! (我通过使用
New-TemporaryFile命令对其进行了一些更改,然后将FullName传递给WriteAllBytes,但我认为这是相同答案的稍微优化的版本!如果你想把答案写下来,我'我会接受,否则我会放弃我的解决方案 -
很高兴成功了!见下文
标签: powershell azure-functions serverless