使用 powershell 将报告上传到 telerik report-server api

问题描述 投票:0回答:1

尝试使用 PowerShell 将报告上传到 Telerik 报告服务器。我可以很好地获取/发布到其他端点。

我不太明白我做错了什么。感谢任何反馈!

            $headers = @{
               "Accept"="application/json"; 
               "Content-Type"="application/x-www-form-urlencoded"
               "Authorization"="bearer 4X8k++++" }

            $httpfile = @{
                Name="$rptName";
                FileName="$rptFileName";
                MediaType="application/x-zip-compressed";
                Buffer="$( Get-Content "$rptFullname" -AsByteStream )";
            } 

            $rptbody = [PSCustomObject]@{
                Name="$rptName";
                Description="$rptDesciption";
                CategoryId="$catagoryId"; 
                ReportFile = $httpfile
            } | ConvertTo-Json

            Write-Debug " ----------rptBody"
            $rptBody | Write-Debug 
            Write-Debug " ----------"

            irm "$($base_uri)/api/reportserver/v2/reports" -Method POST -Headers $headers -Body $rptBody

检查rptBody

 {
  "Name": "rpt1",
  "Description": "uploaded on 08.Aug.23",
  "CategoryId": "04044ss3f4",
  "ReportFile": {
    "Name": "rpt1",
    "FileName": "rpt1.trdp",
    "MediaType": "application/x-zip-compressed",
    "Buffer": "80 75 3 4 2 ++++" } }

错误

{"Message":"请求无效。","ModelState":{"model.Name":["Name 字段为必填项。"],"model.CategoryId":["CategoryId 字段为必填项。 "],"model.ReportFile":["ReportFile 字段为必填项。"]}}

telerik 报告服务器 api 参考 https://docs.telerik.com/report-server/implementer-guide/apis/rest-api/v2/post-api-reportserver-v2-reports

powershell rest telerik
1个回答
0
投票

好的,它可以工作了,必须更改字节流并添加 json 内容类型。如果有人需要迁移 Telerik 报告的方法,我会保留它。我们将制作一个 choco 包来更新服务器。

    $headers = @{
           "Accept"="application/json"; 
           "Content-Type"="application/x-www-form-urlencoded"
           "Authorization"="bearer 4X8k++++" }

        $httpfile = @{
            Name="$rptName";
            FileName="$rptFileName";
            MediaType="application/x-zip-compressed";
            Buffer="$( [convert]::ToBase64String( [IO.File]::ReadAllBytes( "$rptFullName" ) ) )";
        } 

        $rptbody = [PSCustomObject]@{
            Name="$rptName";
            Description="$rptDesciption";
            CategoryId="$catagoryId"; 
            ReportFile = $httpfile
        } | ConvertTo-Json

        irm "$($base_uri)/api/reportserver/v2/reports" -Method POST -Headers $headers -Body $rptBody -ContentType "application/json"
© www.soinside.com 2019 - 2024. All rights reserved.