docs.nestjs.com icon indicating copy to clipboard operation
docs.nestjs.com copied to clipboard

Can you provide examples of uploading files?

Open ZengMingDa opened this issue 8 months ago • 0 comments

Is there an existing issue that is already proposing this?

  • [x] I have searched the existing issues

Is your feature request related to a problem? Please describe it

Can you provide examples of uploading files? I cannot integrate the upload of files.

import GraphQLUpload from "graphql-upload/GraphQLUpload.mjs";
import type FileUpload from "graphql-upload/processRequest.mjs";

or

import { FileUpload, GraphQLUpload } from '@nestjs/graphql';



  @Mutation(() => String)
  async uploadFile(
    @Args({ name: 'file', type: () => GraphQLUpload })
    { createReadStream, filename }: FileUpload
  ): Promise<string> {
    const uploadDir = join(process.cwd(), 'uploads');
    await mkdirp(uploadDir);

    const filePath = join(uploadDir, filename);
    const readStream = createReadStream();
    const writeStream = createWriteStream(filePath);
    await pump(readStream, writeStream);

    return `File saved to: ${filePath}`;
  }

Describe the solution you'd like

I hope to come up with a case study

Teachability, documentation, adoption, migration strategy

https://github.com/jaydenseric/graphql-upload/issues/391#issuecomment-2678412191

This brother doesn't quite understand what I mean

What is the motivation / use case for changing the behavior?

...

ZengMingDa avatar Feb 24 '25 15:02 ZengMingDa