Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
Uploading a file in NestJS does not go through

I wanna upload a File from my React Native App to my API Endpoint that is written in NestJS. I am using the fastify adapter with the fastify-multipart package.

This is how I send the file to my API:

  const data = new FormData();
  const file = new File([blob], "image1");

  console.log(file.size);

  data.append("file", file);

  const result = await axios
    .post("https://myapiurl/settings/upload-avatar", data, {
      headers: {
        "Content-Type": "multipart/form-data",
      },
    })

The console log above brings the following output for an example .png 1210126, so that means in my eyes that the file is correct and the problem lies in the backend.

This is my controller function for the endpoint:

  @Post('upload-avatar')
  async uploadAvatar(@Req() req: fastify.FastifyRequest,@Res() res: fastify.FastifyReply<any>) {
    const parts = req.parts();

    for await (const part of parts) {
      if (part.file) {
        const buffer = await part.toBuffer();
        console.log(buffer.length, buffer.byteLength)
      }
    }

    console.log("done");
  }

I tried around a lot but the end result is always that the buffer length is 0 and I basicly receive an empty file in my backend.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!