BTCpayAPI now supports file upload

Hero image for BTCpayAPI now supports file upload

BTCpayApi Update 03-28-2025

Introduction

I'm continuing to add functionality to BTCpayAPI and BTCpay which is using REST Api(s) to manage my BTCPAY server and LND cloud instance. It is nice to have this just running locally on my home Linux desktop.

Here is the code that implements this functionality.

"Uploadfile" {

$apislug = "api/v1/files"
#$filepath = Split-Path $options
$filename = Split-Path $options -Leaf

# CONST
$CODEPAGE = "iso-8859-1" # alternatives are ASCII, UTF-8

# Read file byte-by-byte
$fileBin = [System.IO.File]::ReadAllBytes($options)

# Convert byte-array to string
$enc = [System.Text.Encoding]::GetEncoding($CODEPAGE)
$fileEnc = $enc.GetString($fileBin)

# We need a boundary (something random() will do best)
$boundary = [System.Guid]::NewGuid().ToString()
$LF = "`r`n"
$bodyLines = (
"--$boundary",
"Content-Disposition: form-data; name=`"file`"; filename=`"$fileName`"",
"Content-Type: application/octet-stream$LF",
$fileEnc,
"--$boundary--$LF"
) -join $LF

$URI = $BTCPayCfg.BTCpayApi.GreenApi.url + $apislug
$apiKeyToken = 'token ' + $script:BTCPAY_API
$headers = @{'Authorization'=$apiKeyToken}

return Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -ContentType "multipart/form-data; boundary=`"$boundary`"" -Body $bodyLines

}

Revision History
VersionDateWhomNotes
0.1.403/28/2025cadaytonAdded UploadFile method to upload a file to the BTCpay server
0.1.303/27/2025cadaytonAdded GetFiles returns listing of files uploaded to BTCpay server
0.1.203/19/2025cadaytonForwardingHistory new parameter total_fees tallys mfees for events returned
0.1.103/18/2025cadaytonForwardingHistory now support additional parameters
0.1.003/15/2025cadaytoninitial release