Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you provide examples of uploading files? #3210

Open
1 task done
ZengMingDa opened this issue Feb 24, 2025 · 0 comments
Open
1 task done

Can you provide examples of uploading files? #3210

ZengMingDa opened this issue Feb 24, 2025 · 0 comments
Labels

Comments

@ZengMingDa
Copy link

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?

...

@kamilmysliwiec kamilmysliwiec transferred this issue from nestjs/graphql Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant