I’m getting an error when I try to upload in GraphQL: “POST body missing, invalid Content-Type, or JSON object has no keys.”

I’m getting an error when I try to upload in GraphQL: “POST body missing, invalid Content-Type, or JSON object has no keys.”


0

My code is correct, but I don’t know what’s happening, I need to upload it with graphQL but I can’t, my resolver code looks like this:

`import { Resolver, Query, Mutation, Arg } from "type-graphql";

import { GraphQLUpload, FileUpload } from "graphql-upload-ts";

@Resolver()
export class CategoryResolver {
@Mutation(() => String)
async uploadImage(@Arg("file", () => GraphQLUpload) file: FileUpload) {
console.log({ file });

    return "message";

}
}`

I already changed the content-type of my apollo server sandbox to multipart/form-data and it gives this error: "POST body missing, invalid Content-Type, or JSON object has no keys." and when I change to application/json this error occurs: "Unexpected token ‘<‘, "<!DOCTYPE "… is not valid JSON" I know that the request has to be made in the multipart/form-data format. I’m adding all the fields correctly, I don’t know what’s happening, the versions are: "@apollo/server": "^4.9.5", "graphql-upload-ts": "^2.1.0", "type- graphql": "2.0.0-beta.1"

Apollo Sandbox

New contributor

Vinicius Barrios is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


Load 4 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *