Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrsauravsahu/blog-graphql-nestjs-fileupload
example code on how to upload a file with multipart requests to GraphQL in nestjs
https://github.com/mrsauravsahu/blog-graphql-nestjs-fileupload
apollo-server apollo-server-express file-upload graphql nestjs
Last synced: about 1 month ago
JSON representation
example code on how to upload a file with multipart requests to GraphQL in nestjs
- Host: GitHub
- URL: https://github.com/mrsauravsahu/blog-graphql-nestjs-fileupload
- Owner: mrsauravsahu
- Created: 2021-10-17T11:26:08.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-11-05T10:26:53.000Z (about 3 years ago)
- Last Synced: 2024-10-14T08:34:14.787Z (3 months ago)
- Topics: apollo-server, apollo-server-express, file-upload, graphql, nestjs
- Language: TypeScript
- Homepage: https://dev.to/mrsauravsahu/file-uploads-on-graphql-why-or-why-not-ek0
- Size: 1.97 MB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# blog-graphql-nestjs-fileupload
upload file via GraphQL with multipart requests.
the graphql queries and mutations are as follows -
```graphql
type Query {
author(id: Int!): Person!
}type Mutation {
coverPhoto(file: Upload!): Int!
}
```the mutation accepts file and returns back the length in bytes.
The data stored in the app is in-memory and is **not** recommended for production.
To run the mutation, you can use Postman or directly use this cURL command at the root of the project (it has a sample image)
```bash
curl --location --request POST 'http://localhost:8080/graphql' \
--form 'operations="{\"query\": \"mutation updateProfilePhoto($file: Upload!) { coverPhoto(file: $file)} \", \"variables\": {\"file\": null}}"' \
--form 'map="{\"0\": [\"variables.file\"]}"' \
--form '0=@"./assets/grand-palais-mrsauravsahu.jpg"'
```this will return the length of the file in bytes.
If you import this request in Postman, make sure the file path is correct. 👍
-S