-
-
Notifications
You must be signed in to change notification settings - Fork 531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty c.req.raw body for application/x-www-form-urlencoded #2695
Comments
looks no problem...? constructor(
request: Request,
path: string = '/',
matchResult: Result<[unknown, RouterRoute]> = [[]]
) {
this.raw = request
this.path = path
this.#matchResult = matchResult
this.#validatedData = {}
} private dispatch(
request: Request,
executionCtx: ExecutionContext | FetchEventLike | undefined,
env: E['Bindings'],
method: string
): Response | Promise<Response> {
// Handle HEAD method
if (method === 'HEAD') {
return (async () =>
new Response(null, await this.dispatch(request, executionCtx, env, 'GET')))()
}
const path = this.getPath(request, { env })
const matchResult = this.matchRoute(method, path)
const c = new Context(new HonoRequest(request, path, matchResult), {
env,
executionCtx,
notFoundHandler: this.notFoundHandler,
})
... |
That problem is only in OpenAPIHono enviroment? |
hi @LuisMalhadas async function parseFormData<T extends BodyData = BodyData>(
request: HonoRequest | Request,
options: ParseBodyOptions
): Promise<T> {
const formData = await (request as Request).formData()
if (formData) {
return convertFormDataToBodyData<T>(formData, options)
}
// cause problem
return {} as T
} |
request is avaible. |
It is likely that the formData you submitted is corrupted.. function convertFormDataToBodyData<T extends BodyData = BodyData>(
formData: FormData,
options: ParseBodyOptions
): T {
const form: BodyData = {}
formData.forEach((value, key) => {
const shouldParseAllValues = options.all || key.endsWith('[]')
if (!shouldParseAllValues) {
form[key] = value
} else {
handleParsingAllValues(form, key, value)
}
})
return form as T
} |
@EdamAme-x First of all thanks for paying attention to it and replying. Either way... I feel it is an issue with OpenAPIHono, as well. speech2text_app.openapi(
createRoute({
method: 'post',
path: '',
description: 'Transcribes an audio file to text',
request: {
params: z.object({
language: z.string().optional().openapi({ description: 'The language of the output text.'})
}),
body: {
content: {
'application/x-www-form-urlencoded': {
schema: z.string().openapi({ format: 'binary', description: 'The audio file to transcribe' })
}
},
required: true
},
headers: auth_schema
},
responses: {
200: {
description: 'The full text of the audio file',
content: {
'application/json': {
schema: z.object({
text: z.string().openapi({ description: 'The transcribed text' })
})
}
}
},
... To give more details ...
$endpoint = $this->base_url."/speech2text";
$options = array();
$header = array(
'Authorization:' . .......,
'mimetype:' . $filemime,
);
$curl = new \curl(['ignoresecurity' => true]);
$curl->setHeader($header);
$curl->setopt($options);
$response = $curl->post($endpoint, base64_encode($curlFile));
... It is an audio file. ...
const audiodata = new FormData()
const audio = atob(req.body??'')
const buffer = new ArrayBuffer(audio.length)
const view = new Uint8Array(buffer)
for (let i = 0; i < audio.length; i++) {
view[i] = audio.charCodeAt(i)
}
const blob = new Blob([view], { type: req.headers?.mimetype as string })
audiodata.append('audio_file', blob, req.headers?.mimetype as string) That is working (for now), but implies I load the file all into memory.
Shouldn't this work? |
This works well: import { OpenAPIHono } from '@hono/zod-openapi'
const app = new OpenAPIHono()
app.post('/', async (c) => {
const bod = await c.req.parseBody()
return c.json(bod)
})
export default app I don't understand this issue perfectly, but I think it's not a bug. I'll close it. If you still have a problem, please provide a minimal project to reproduce it. |
What version of Hono are you using?
4.3.6
What runtime/platform is your app running on?
bun 1.1.8
What steps can reproduce the bug?
What is the expected behavior?
What do you see instead?
Additional information
I can get the body using plain bun.
The text was updated successfully, but these errors were encountered: