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

upload large file causing Error: "Payload content length greater than maximum allowed: 1048576" #3354

Closed
Prosen-Ghosh opened this issue Sep 29, 2019 · 4 comments

Comments

@Prosen-Ghosh
Copy link

Apollo Server Setup

const serverApollo = new ApolloServer({
    typeDefs,
    resolvers,
    schemaDirectives,
    uploads: {
        maxFieldSize: 52428800, //bytes = 50MB
        maxFileSize: 52428800,
        maxFiles: 10
    },
    formatError`
});

Package name

"hapi": "^17.8.5"
"apollo-server-hapi": "^2.4.8"

Actual Behavior

Less then 1MB File is uploading successfully. If the file size is gather then 1MB then i get the response is as given bellow.

{
    "statusCode": 413,
    "error": "Request Entity Too Large",
    "message": "Payload content length greater than maximum allowed: 1048576"
}

Expected Behavior

I expect file uploads as described in the "File uploads" documentation to work with apollo-server-hapi.

@abernix
Copy link
Member

abernix commented Oct 2, 2019

You have syntax errors in your Apollo Server Setup, but you've also left off the important bit after that to see how you're using serverApollo with applyMiddleware currently.

Regardless, 1MB is the default limit by Hapi 17. If you want to change it — much like any Hapi middleware — you'll need to adjust Hapi's maxBytes by setting it to something higher if you want to send more bytes than that.

For apollo-server-hapi, you can do this via applyMiddleware's route parameter (which is passed to Hapi itself):

serverApollo.applyMiddleware({
  app,
  route: {
    payload: {
      maxBytes: 52428800,
    },
  },
});

If you have any other questions, please ask in the Apollo Server channel of Apollo's Spectrum.chat.

@Prosen-Ghosh
Copy link
Author

Prosen-Ghosh commented Oct 5, 2019

here is my full apollo server setup code

const serverApollo = new ApolloServer({
    typeDefs,
    resolvers,
    schemaDirectives,
    formatError,
    uploads: {
        maxFieldSize: 52428800, //bytes = 50MB
        maxFileSize: 52428800,
        maxFiles: 10
    }
});
await serverApollo.applyMiddleware({
    app,
    route: {
        payload: {
           maxBytes: 52428800
        }
    }
});
await serverApollo.installSubscriptionHandlers(app.listener);

after passing route object in applyMiddleware it is throwing Error on apollo server! { AssertionError [ERR_ASSERTION]: Cannot set payload settings on HEAD or GET request: GET /graphql

my setup is much like this

@abernix
Copy link
Member

abernix commented Oct 11, 2019

I see. As we move toward Apollo Server 3.x, we won't be able to give this any attention ourselves. If this is important to you, we would accept a PR which (cleanly) splits the route registration into separate GET and POST registrations (i.e. rather than method: ['GET', 'POST'], a separate method: 'GET' and method: 'POST') and omits the payload option on the GET:

}
server.route({
method: ['GET', 'POST'],
path: options.path || '/graphql',

It should also add tests. If that's something you're willing to do, I'd encourage you to first try it locally to ensure it will work, prior to opening the PR.

@rpandey
Copy link

rpandey commented Jan 11, 2020

here is my full apollo server setup code

const serverApollo = new ApolloServer({
    typeDefs,
    resolvers,
    schemaDirectives,
    formatError,
    uploads: {
        maxFieldSize: 52428800, //bytes = 50MB
        maxFileSize: 52428800,
        maxFiles: 10
    }
});
await serverApollo.applyMiddleware({
    app,
    route: {
        payload: {
           maxBytes: 52428800
        }
    }
});
await serverApollo.installSubscriptionHandlers(app.listener);

after passing route object in applyMiddleware it is throwing Error on apollo server! { AssertionError [ERR_ASSERTION]: Cannot set payload settings on HEAD or GET request: GET /graphql

my setup is much like this

Yes, I'm facing exact same error.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants