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

86
Views
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 answers
Answer question

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 Report
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!