none
Powershell API- Upload PDF to Endpoint from Local Machine RRS feed

  • Question

  • Hello, I am running into issues getting this to work. 

     What I'm trying to do is upload a "PDF" to our system using API commands in Powershell. I've been able to upload "documents" from my disk drive, but when I try to view them they are either "Document not found" or "Cannot open this PDF" or ""The input is not a valid Base-64 string as it contains a non-base 64 character". If it is successful, the PDF is blank. I've tried different methods: encoding/decoding in a variety of ways, I've tried opening it in several different programs- doesn't seem like nothing is working and I'm losing sleep.

    Below is my code for just straight upload:

    $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

    Below is my code I tried using encoding/decoding:

    $fileName = "C:\files\Test1.pdf"
    $fileContent = get-content -raw $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
    • Moved by Baron Bi Tuesday, April 17, 2018 9:47 AM PowerShell issue
    Saturday, April 14, 2018 5:56 PM

All replies