examples icon indicating copy to clipboard operation
examples copied to clipboard

Provide a clear example on how to upload files

Open RiadhAdrani opened this issue 1 year ago • 0 comments

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 : image

image

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.

RiadhAdrani avatar Feb 09 '24 23:02 RiadhAdrani