8000 Problems with getting req.file.size in express · Issue #202 · anacronw/multer-s3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Problems with getting req.file.size in express #202

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

Open
ghost opened this issue Mar 4, 2023 · 1 comment
Open

Problems with getting req.file.size in express #202

ghost opened this issue Mar 4, 2023 · 1 comment

Comments

@ghost
Copy link
ghost commented Mar 4, 2023

That is the code I use as middlewear

I try to access the file size at the:
req.file = {
name: file.originalname,
encoding: file.encoding,
type: file.mimetype,
bucketFileKey: keyName,
};

Multer itself
image
image

Router integration
image

In text form:
const multerS3 = require("multer-s3");
const multer = require("multer");
const uuid = require("uuid");

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

const s3 = new S3Client({
region: "eu",
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID || "",
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || "",
},
endpoint: process.env.AWS_END_POINT,
forcePathStyle: true,
});

export const upload = multer({
storage: multerS3({
s3: s3,
bucket: "user-files",
acl: "private",
key: function (req: any, file: any, cb: any) {
const uniqueFileName = uuid.v4();
const keyName = ${req.user.email}/${uniqueFileName};
req.file = {
name: file.originalname,
encoding: file.encoding,
type: file.mimetype,
bucketFileKey: keyName,
};

  cb(null, keyName);
},
metadata: function (req: any, file: any, cb: any) {
  cb(null, { size: file.size });
},

}),
});

I integrate it that way

router.post(
"/upload",
upload.fields([{ name: "file" }, { name: "folder" }]),
postUploadFile
);

@ghost
Copy link
Author
ghost commented Mar 4, 2023

Okay the point was, when we accept more than 1 form-data fields, we get the files data that way:
image
So you gotta access it that way req.files.file[0]

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

0 participants
0