Skip to content

Can you provide examples of uploading files? #3210

Open
@ZengMingDa

Description

@ZengMingDa

Is there an existing issue that is already proposing this?

  • 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

jaydenseric/graphql-upload#391 (comment)

This brother doesn't quite understand what I mean

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

...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions