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

Issue with uploading PDF to S3 with apollo-server-lambda #303

Closed
yevhenii-kas-oppizi opened this issue May 11, 2022 · 1 comment
Closed

Comments

@yevhenii-kas-oppizi
Copy link

I try to upload a pdf file to S3, and files are uploading, but files have blank pages or are even not open.

I tried to apply the same logic with uploading on the express server without the serverless framework, and it works.
I don't understand how I should upload my pdf's to S3 from apollo-server-lambda serverless server,
So maybe you can help with some tip

Here is my code, how i run the server:

export const handler = server.createHandler({
  expressAppFromMiddleware(middleware) {
    const app = express();
    app.use(graphqlUploadExpress());
    app.use(middleware);
    return app;
  },
})

Here is my code, how i save the file to S3:

const createUploadStream = (key) => {
  const pass = new stream.PassThrough();
  return {
    writeStream: pass,
    promise: s3
      .upload({
        Bucket: 'my-bucket',
        Key: key,
        Body: pass
      })
      .promise()
  };
}

const resolvers = {
  Upload: GraphQLUpload,
  Mutation: {
    singleUpload: async (parent, { file }) => {
      const { createReadStream, filename, mimetype, encoding } = await file;
      const stream = createReadStream()

      const filePath = filename

      const uploadStream = createUploadStream(filePath);

      stream.pipe(uploadStream.writeStream);

      const result = await uploadStream.promise;

    },
  },
};
@jaydenseric
Copy link
Owner

graphql-upload is designed to work with a multipart request stream, which is not the way AWS Lambda works. Your request for assistance is better directed at the apollo-server-lambda maintainers and community. You can track if we ever produce an AWS Lambda implementation here which we could then support at #155 .

I tried to apply the same logic with uploading on the express server without the serverless framework, and it works.

That's is indeed a clue that maybe your resolver code is fine, and there is something wrong with the server infrastructure or apollo-server-lambda, but I'm not in a good position to speculate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants