Skip to content

Instantly share code, notes, and snippets.

@Shaxadhere
Created October 5, 2022 22:54
Show Gist options
  • Save Shaxadhere/e6be96887915d519b711e0d2f66eff5d to your computer and use it in GitHub Desktop.
Save Shaxadhere/e6be96887915d519b711e0d2f66eff5d to your computer and use it in GitHub Desktop.
upload object to wasabi cloud with multer
const { S3Client } = require('@aws-sdk/client-s3');
const AWS = require('aws-sdk');
const multer = require('multer')
const multerS3 = require('multer-s3')
const ep = new AWS.Endpoint('s3.wasabisys.com');
const { generateString } = require("./index")
const s3 = new S3Client({
endpoint: ep,
region: process.env.WASABI_REGION,
credentials: {
accessKeyId: process.env.WASABI_ACCESS_KEY_ID,
secretAccessKey: process.env.WASABI_SECRET_ACCESS_KEY,
},
sslEnabled: false,
s3ForcePathStyle: true,
signatureVersion: 'v4',
});
module.exports = uploadToWasabi = multer({
storage: multerS3({
s3: s3,
bucket: process.env.bucketName,
contentType: multerS3.AUTO_CONTENT_TYPE,
acl: 'public-read',
metadata: function (req, file, cb) {
cb(null, { fieldName: file.fieldname });
},
key: function (req, file, cb) {
const fileName = generateString(18) + file.originalname.split(".").pop()
req.body.uploaded = fileName
cb(null, fileName);
},
}),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment