NestJs Fastify 配置文件上传

在Nestjs + Fastify项目中,为了解决使用FileInterceptor时遇到的'TypeError: req.pipe is not a function'错误,通过在Stack Overflow上找到的解决方案,需要引入fastify-multipart插件来支持文件上传。该插件使得Fastify能够处理multipart/form-data格式,从而实现文件上传功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本来项目用的是 Nestjs + Fastify, 因项目需要文件上传功能, 一开始使用的是 FileInterceptor 但是会报  "TypeError: req.pipe is not a function" 这个错误. 偶然中在 stack overflow 找到了这个问题的解决方法. How to get rid of "TypeError: req.pipe is not a function" nestjs and fastify

根据项目修改后的文件上传代码

import { Injectable } from "@nestjs/common";
import { rootPath } from "src/common/util/root-path";
import CraftEntity from "src/entities/admin/bs-craft.entity";
import { Connection } from "typeorm";
const path= require("path");
const fs = require('fs');

@Injectable()
export class SysFileService {
  constructor(
    private readonly connection: Connection) { }

  async clearFiles() {
    const recordFiles: Set<string> = new Set();

    const all 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值