You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While sending an audio file within the request body, I'm receiving the following error:
{
"error": "binding error: error parsing request body: invalid character 'R' looking for beginning of value"
}
As I understand, the audio file is parsed as a string and not the binary file -- the "R" is from string "RIFF" file header. The question is whether I could bind it as an audio/wav type as described below?
I've run into that too. Here's a workaround until fizz and tonic get updated.
So, the binding error happens because tonic tries to use JSON unmarshal when it sees a handler with a request object. To get around it, you gotta set up a custom binding hook:
typeEvaluationstruct {
UserIDstring`query:"userId" validate:"required" description:"Id of user"`
}
// implement Binder for your request structfunc (e*Evaluation) ShouldBind() bool {
returnfalse
}
typeBinderinterface {
ShouldBind() bool
}
funcCustomBindHook(c*gin.Context, inany) error {
ifbinder, ok:=in.(Binder); ok {
if!binder.ShouldBind() {
returnnil
}
}
returntonic.DefaultBindingHook(c, in)
}
// add following code somewhere when setup routetonic.SetBindHook(CustomBindHook)
Next, since you cannot set custom content types in fizz right now, you'll need to tweak the OpenAPI schema object directly. Because it's a bit of a hassle, I won't be writing the code here.
While sending an audio file within the request body, I'm receiving the following error:
As I understand, the audio file is parsed as a
string
and not the binary file -- the "R" is from string "RIFF" file header. The question is whether I could bind it as anaudio/wav
type as described below?The request looks like this:
So I send
userId
as a param and binary audio file in the body asaudio/wav
content type.Code-wise, the handler functions look like this:
and the structs:
BTW While generating OpenAPI YAML, the part I'm interested in looks like this:
and I need this:
The text was updated successfully, but these errors were encountered: