我遇到了一个问题,试图让它发挥作用。我要做的是使用Powershell中的API命令将“PDF”上传到我们的系统。我已经能够从我的磁盘驱动器上传“文档”,但是当我尝试查看它们时,它们是“找不到文档”或“无法打开此PDF”或“”输入不是有效的Base-64字符串因为它包含一个非基础的64个字符“。我尝试了不同的方法:以各种方式编码/解码,我尝试在几个不同的程序中打开它 - 似乎没有什么工作,我是失眠。
以下是我直接上传的代码:
$fileName = "C:\files\Test1.pdf"
$data = ConvertTo-Json @{
encrypted="false";
allowSaveBinaryData="True";
binaryData=$fileName;
divider="Expense Report";
isMultipageImage="true";
extension="pdf";
name="Test1.pdf";
relProjectId="31";
}
$addproject="https://ENDPOINT URL.com/v4/documents/597?guid=$temp&fbsite=https://MYURL.com/"
Invoke-RestMethod -ContentType 'application/json' -Method PUT -Body $data -Uri $addproject
以下是我尝试使用编码/解码的代码:
$fileName = "C:\files\Test1.pdf"
$fileContent = get-content $fileName
$fileContentBytes = [System.Text.Encoding]::Unicode.GetBytes($fileContent)
$fileContentEncoded = [System.Convert]::ToBase64String($fileContentBytes)
$data = ConvertTo-Json @{
encrypted="false";
allowSaveBinaryData="True";
binaryData=$fileContentEncoded;
divider="Expense Report";
isMultipageImage="true";
extension="pdf";
name="Test1.pdf";
relProjectId="31";
}
$addproject="https://ENDPOINT URL.com/v4/documents/597?guid=$temp&fbsite=https://MYURL.com/"
Invoke-RestMethod -ContentType 'application/json' -Method PUT -Body $data -Uri $addproject
答案 0 :(得分:1)
我用这个::
想出来了$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", 'application/pdf')
$fileName="C:\files\$item2"
$fileContent = get-content -Raw $fileName
$fileContentBytes = [System.Text.Encoding]::Default.GetBytes($fileContent)
$fileContentEncoded = [System.Convert]::ToBase64String($fileContentBytes)
$data = ConvertTo-Json @{
encrypted="false";
allowSaveBinaryData="true";
binaryData="$fileContentEncoded"
divider="Expense Report";
extension="pdf";
name="$fileContentEncoded";
relProjectId="31";
fileID="597"
}
$var2[$i2]="https://MY ENDPOINT /v4/documents/597?guid=$AUTHtemp&fbsite=https://XXXXXXXXX/"
Invoke-RestMethod -headers $headers -ContentType 'application/json' -Method PUT -body $data -Uri $var2[$i2]}