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
}
| Version | Date | Whom | Notes |
|---|---|---|---|
| 0.1.4 | 03/28/2025 | cadayton | Added UploadFile method to upload a file to the BTCpay server |
| 0.1.3 | 03/27/2025 | cadayton | Added GetFiles returns listing of files uploaded to BTCpay server |
| 0.1.2 | 03/19/2025 | cadayton | ForwardingHistory new parameter total_feestallys mfees for events returned |
| 0.1.1 | 03/18/2025 | cadayton | ForwardingHistory now support additional parameters |
| 0.1.0 | 03/15/2025 | cadayton | initial release |