Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

370
Vistas
Fastify - How to get non-file fields using fastify-multipart

How to access text from request that are non-file fields? (I am using Insomia)

Our request using Insomia enter image description here

We are able to access file fields by looping through parts. using const parts = await req.files();.

index.js

    import Fastify from "fastify";
    import FastifyMultipart from "fastify-multipart";
    
    export const fastify = await Fastify();
    fastify.register(FastifyMultipart);

controllers/property.js

    export const addProperty = async function (req, res) {
      try {
        // WE ACCESS FILES OF MULTIPART FORM REQUEST HERE
        const parts = await req.files();
        for await (const data of parts) {
          console.log("*******File being access**********");
          console.log(data.filename); // access file name
          ...
        }
        // HOW DO WE ACCESS OTHER *NON_FILES* FIELDS?
        ...
        res.status(201).send({ message: "Property Added!." });
      } catch (error) {
        res.send(error);
      }
    };

in the controllers script we access files using await req.files();.

How do we access the fields that are non-file, like text

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

There are two ways to get other data it is given in the docs https://github.com/fastify/fastify-multipart

  1. pass the other fields before file Passing the name before image

Now you can access name in data.fields

const data = await req.file();
console.log(data.fields.name.value); // virender
  1. you can attach it to body
fastify.register(require('fastify-multipart'), { attachFieldsToBody: true });
const file = req.body.image1;
const name = req.body.name.value
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda