gpt4 book ai didi

rest - Powershell:Out-File - 访问路径被拒绝

转载 作者:行者123 更新时间:2023-12-05 01:00:37 28 4
gpt4 key购买 nike

我有一个用于下载 PDF 文件的 REST 调用 (POST)。 API 调用以 PDF 文件的二进制版本响应。我想在我的机器上将文件保存为 .pdf。但是,我收到一个错误:

Out-File : Access to the path 'C:\Users\my-name\Documents\Tests' is denied.At C:\Users\my-name\Documents\Tests\TEST-WITH-LOOP.ps1:132 char:149+ ... questBody | Out-File -FilePath ("C:\Users\my-name\Documents\Tests+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : OpenError: (:) [Out-File], UnauthorizedAccessException    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand

Response body header from POSTMAN:

Content-Disposition →attachment; filename="Report-01_29_14-28.pdf"Content-Type →application/octet-streamDataServiceVersion →2.0Date →Mon, 29 Jan 2018 21:51:31 GMTDate →Mon, 29 Jan 2018 21:51:31 GMTServer →Jetty(9.3.7.v20160115NeotysEdition.30)Transfer-Encoding →chunked

Command:

$DownloadReportResponse = Invoke-RestMethod -Method Post -Uri $DownloadReportUrl -ContentType "application/json" -Body $DownloadReportRequestBody |
Out-File -FilePath ("C:\Users\my-name\Documents\Tests") -Force

问题:如何将其以 .pdf 格式保存到我的机器中,或者作为电子邮件的附件包含在内?

最佳答案

嗯,这个错误有点误导。您正在尝试将输出文件创建为 C:\Users\my-name\Documents\Tests,但该文件已作为目录存在,因此存在访问冲突。使用完整路径创建文件:

Invoke-RestMethod ... |
Out-File "C:\Users\my-name\Documents\Tests\Report-01_29_14-28.pdf"

关于rest - Powershell:Out-File - 访问路径被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48511400/

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