jaydenseric / graphql-upload

Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
https://npm.im/graphql-upload
MIT License
1.43k stars 131 forks source link

PayloadTooLargeError: File truncated as it exceeds the byte size limit. #300

Closed AlexJohnSadowski closed 2 years ago

AlexJohnSadowski commented 2 years ago

I know the error is quite old, but I think it's still relevant. Or something's missing from the documentation, because I cannot find the way to catch that error in my application, hence it crashes the server. Try-catch doesn't work, Promises don't work. What's the solution to handle that? Read bunch of threads, but none of it helps. Ofc. if the file is smaller all works perfectly.

index.js

 async function startServer() {
    const server = new ApolloServer({
      typeDefs,
      resolvers,
      context: ({ req }): Dependencies => new Dependencies(container),
    });
    await server.start();

    const app = express();

    // This middleware should be added before calling `applyMiddleware`.
    app.use(graphqlUploadExpress({ maxFileSize: 1000000, maxFiles: 10 }));

    server.applyMiddleware({ app });

    await new Promise<void>((r) => app.listen({ port: process.env.PORT || 4000 }, r));

    console.log(`🚀 Server ready at http://localhost:${process.env.PORT || 4000}${server.graphqlPath}`);
  }
  await startServer();
})();

Mutation:

public async photoUpload(file: Photo) {
    try {
      const { createReadStream, filename, mimetype, encoding } = await file;
      const stream = createReadStream();

      if (mimetype === 'image/png' || mimetype === 'image/jpg' || mimetype === 'image/jpeg') {
        this.azureBlobStorageService.uploadFile('images', stream);
        return { filename, mimetype, encoding };
      } else return console.log('Wrong file type or the file is too big!');
    } catch (error) {
      console.log(error);
    }
  }
}

Error:

/node_modules/graphql-upload/public/processRequest.js:264

 fileError = createError(
                    ^
PayloadTooLargeError: File truncated as it exceeds the 1000000 byte size limit.

Package.json

  "apollo-server": "^3.4.0",
    "apollo-server-express": "^3.6.7",
    "fs-capacitor": "^7.0.1" (installing it doesn't change anything)
    "graphql": "^15.7.2",
    "graphql-upload": "^13.0.0",
AidaRvi commented 2 years ago

What happen to this question? I have the same issue here @AlexJohnSadowski

reda-xk7 commented 1 year ago

I have the same issue here @AidaRvi @AlexJohnSadowski

rasmus-rudling commented 1 year ago

I have the same issue, any solutions @AidaRvi @reda-xk7 @AlexJohnSadowski ?

mozsinrb commented 1 year ago

any update on this issue?

paramsinghvc commented 1 year ago

I did some digging, and found in processRequest.js that createReadStream method is being called once before stream.on('limit',...) emits an error. So, the thrown error is going no where!

Not sure what's the solution here or if its an implementation bug? @jaydenseric

Screenshot 2023-05-10 at 10 40 53 Screenshot 2023-05-10 at 10 41 10