Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

89
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda