Bug: Incorrect Implementation of --file
Option in kn func invoke
#2545
Labels
kind/bug
Categorizes issue or PR as related to a bug.
kind/good-first-issue
Denotes an issue ready for a new contributor.
Summary
The implementation of the
--file
option in thekn func invoke
command encodes the file content as a base64 string, but it is not decoded before being sent, resulting in errors when invoking functions via HTTP or CloudEvents.Steps to Reproduce
test.json
, with the following content:Analysis
The sequence of operations in
func/cmd/invoke.go
shows that when--file
is specified, the file content gets read and encoded as a base64 string (m.Data
), but this encoded data is not being decoded before being sent in the request. This inconsistency leads to the errors observed.Relevant code snippet from
func/cmd/invoke.go
:The data is sent without decoding in the
sendEvent
andsendPost
functions located infunc/pkg/functions/invoke.go
. For example, in thesendEvent
function, the decoding code is as follows:At this point,
m.Data
is still a base64 string (e.g.,ewogICAgImlkIjogMTIzCn0=
), which cannot be decoded into JSON.Expected Behavior
When using the --file option, the command should read the content of the specified file and send it in the same format as if the --data option had been provided.
Environment
The text was updated successfully, but these errors were encountered: