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

Getting Missing required key 'Key' in params Error, #184

Open
binjahid opened this issue Jul 10, 2022 · 4 comments
Open

Getting Missing required key 'Key' in params Error, #184

binjahid opened this issue Jul 10, 2022 · 4 comments

Comments

@binjahid
Copy link

I have copied the exact code from the official documentation but still getting this error.

I have tried by installing asw-sdk and aws-sdk-client both give same error.

const upload = multer({ storage: multerS3({ s3, bucket: bucketName, acl: "public-read", metadata: (req, file, cb) => { cb(null, { fieldName: file.fieldname }); }, key: (req, file, cb) => { cb(null, file.originalname); }, }), });

Here clearly i have declared the key but getting the same error. Could anyone please tell me a solution.?

@accounts-alphasophia
Copy link

I am receiving exactly the same error, it's very strange

@LinusU
Copy link
Collaborator

LinusU commented Aug 1, 2022

Are you using the @aws-sdk/client-s3 package?

@accounts-alphasophia
Copy link

accounts-alphasophia commented Aug 1, 2022

I am!

My multer configuration looks as such:

const multerStorageS3 = multerS3({
  s3: getS3Client(),
  bucket: process.env.awsS3Bucket as string,
  key: multerFileName
});

With the key-CB function:

export const multerFileName = (
  req: Request,
  file: Express.Multer.File,
  callback: (error: Error | null, filename: string) => void
) => {
  const ext: string = ".csv";
  crypto.randomBytes(16, (err: Error | null, raw: Buffer) => {
    if (!err && raw) {
      callback(null, raw.toString("hex") + ext);
    } else {
      callback(err, file.filename);
    }
  });
};

and the S3 client from:

import { S3Client, S3ClientConfig, GetObjectCommand } from "@aws-sdk/client-s3";

// Defines S3 client
const s3Config: S3ClientConfig = { region: "us-east-1" }
const s3Client: S3Client = new S3Client(s3Config);

export const getS3Client = (): S3Client => {
  return s3Client;
}

@accounts-alphasophia
Copy link

accounts-alphasophia commented Aug 1, 2022

I have tried to trace down the problem. When executon reaches line 192 in the index.js of the multer-s3 package (executing the S3Storage.prototype._handleFile) to create the params dictionary the Key variable is set as you can see on the picture below. The error must be happening later downstream after creating the Upload object.. It's strange
Screenshot 2022-08-01 at 15 54 07

Edit: Turns out, the files are committed to S3! The error is thrown on the "way back", not on the way there. The error is thown by @aws-sdk/client-s3/dist-cjs/protocols/Aws_restXml.js.. Still bad though, as it crashes my entire tool

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

3 participants