本来项目用的是 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