【发布时间】:2022-01-30 15:13:12
【问题描述】:
我有点压力,因为我不知道为什么会出现这个错误,我正在创建一个迷你应用程序,人们可以在其中上传他们的照片,但对于后端部分我不太了解如何做到这一点,我我正在用 fastify 构建它,这就是我所做的
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;
}
}
在这里我正在创建上传图片的路线,当我上传图片时它会给我一个内部错误,如果有人可以帮助我,我将非常感激: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;
这是我正在做的项目的git,大家看一下:
这是我的邮递员示例
///
【问题讨论】:
-
堆栈跟踪在哪里?
-
堆栈跟踪?
-
对不起,我对后端有点陌生,有些东西看不懂哈哈
-
堆栈跟踪是您在控制台中看到的错误。这有助于我们了解正在发生的事情
-
哦好的,我会上传的
标签: javascript node.js typescript fastify