Skip to content

Correct way to add PDF attachments by file in New-TrelloCard #22

Description

@user8446

Hi Adam,

I have tried -fileSource "C:Path\Path\File.pdf"

and

$File = Get-Item -Path "C:Path\Path\File.pdf"
-fileSource $File

and

$File = [IO.File]::ReadAllBytes("C:Path\Path\File.pdf")
-fileSource $File

and

added 'ContentType' = 'multipart/form-data' to the $RestParams for the Invoke-RestMethod API call.

None work. Removing -fileSource allows the new card to be created. What is the correct way or syntax to add an attachment via New-TrelloCard?
My guess is this has something to do with the encoding as Add-TrelloCardAttachment works fine with .txt but fails with PDF

Update:
I figured it out doing the API call direct. The file needs to be in a form using system.io.fileinfo. I'm on PowerShell 7 and I believe you might have to get into some .NET to make it work on PS5.1.

$FORM = @{
    idList     = "xxxxxx"
    pos        = "top"
    name       = "TestTest"
    fileSource = [system.io.fileinfo]"C:\Path\Path\File.pdf"
}

Invoke-RestMethod -Method Post -Uri "https://api.trello.com/1/cards?$APIKEY" -Form $FORM

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions