examples
examples copied to clipboard
Provide a clear example on how to upload files
I am using hono (v3.12.6) in some personal projects lately, it is simple and fun, but when it comes to file handling, I am having some trouble and was not able to figure it out.
I followed the instructions here but with no results :
// ... handlers
.post('/:id/file', async (ctx: AppAuthContext) => {
const user = ctx.get('user');
const projectId = ctx.req.param('id');
const parsed = await ctx.req.parseBody();
const file = parsed['file'] as File;
const form = await ctx.req.formData();
const body = {
type: form.get('type') as ProjectType,
};
const json = await createProjectFile(user, projectId, file, body);
return ctx.json(json);
});
and this is my postman request :
Maybe this is not the correct place for this issue, but I think that a clear example can prevent a lot of headaches.
Thank you.