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

85
Vistas
How to add images to a database with fastify ts

I'm a little stressed because I have no idea why this error, I'm creating a mini app where people can upload their photos, but for the backend part I don't understand very well how to do that, I'm building it with fastify- ts this is what i did

import fp from "fastify-plugin";
import fastifySocket from "fastify-socket.io";
import SocketConnect from "../events/connections";
import fastifyCors from "fastify-cors";
import multer from "fastify-multer";
import { File, FilesObject } from "fastify-multer/lib/interfaces";

type FilesInRequest = FilesObject | Partial<File>[];

export interface SupportPluginOptions {}

export default fp<SupportPluginOptions>(async (fastify, opts) => {
  fastify.decorate("someSupport", function () {
    return "hugs";
  });

  void fastify.register(fastifySocket);
  void fastify.register(fastifyCors);
  void fastify.register(SocketConnect);

  void fastify.register(multer.contentParser);

});

declare module "fastify" {
  export interface FastifyInstance {
    someSupport(): string;

  }
}

declare module "fastify" {
  export interface FastifyRequest {
    files: FilesInRequest;
  }
}

Here I am creating the route to upload the image, when I upload an image it gives me an internal error, if someone can help me, I would really appreciate it :DDD

import { FastifyPluginAsync } from "fastify";
import multer from "fastify-multer";

const upload = multer({ dest: "upload" });

const publication: FastifyPluginAsync = async (fastify, options) => {
  fastify.post(
    "/create",
    {
      preHandler: upload.single("avatar"),
    },
    async (request, reply) => {
      const { files } = request;

      console.log(files);
      return reply.code(200).send("SUCCESS");
    }
  );
};

export default publication;

bug photo

This is the git of the project I'm doing, so take a look:

bug Photo Two

This is my example with postman

bug postman One

///

Bug postman Two

https://github.com/TioElvis/RedSocial

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The upload.single("avatar"), sentence says that you are expecting an avatar field, but in your postman call you don't set the KEY value in the body tab.

postman key

This will solve.

This is the curl command:

curl --location --request GET 'http://localhost:8080/publication/create' \
--form 'avatar=@"/Pictures/60iu3g.gif"'
about 4 years ago · Juan Pablo Isaza 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