How to use the multer-s3.AUTO_CONTENT_TYPE function in multer-s3

To help you get started, we’ve selected a few multer-s3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lskjs / lskjs / packages / upload / src / server.js View on Github external
getS3Storage() {
    return multerS3({
      s3: this.s3,
      bucket: this.config.s3.bucket,
      contentType: multerS3.AUTO_CONTENT_TYPE,
      acl: 'public-read',
      key3: (req, file, cb) => {
        const filename = nodepath.parse(file.originalname);
        // console.log({ req, file });
        // console.log(`avatar_${req.user._id}.${filename.ext}`);
        cb(null, `avatar_${req.user._id}.${filename.ext}`);
      },
      key: async (req, file, cb) => {
        let filename;
        try {
          // console.log('req, file', file);
          filename = this.getFilePath(req, file);
          // console.log('filename', filename);
          filename = filename.replace(/\//g, '__');
          // console.log('filename2', filename);
        } catch (err) {
github koddsson / micropub-media-endpoint / app.js View on Github external
contentType(req, file, cb) {
      // A hack that pipes the output stream through the exif transformer before after we detect the content type
      // of the stream but before we send it to S3
      multerS3.AUTO_CONTENT_TYPE(req, file, function(_, mime, outputStream) {
        cb(null, mime, outputStream.pipe(new ExifTransformer({readableObjectMode: true, writableObjectMode: true})))
      })
    },
    cacheControl: 'max-age=31536000',
github ditojs / dito / packages / server / src / storage / S3Storage.js View on Github external
name,
      s3,
      acl,
      bucket,
      contentType,
      ...options
    } = config
    this.s3 = new aws.S3(s3)
    this.acl = acl
    this.bucket = bucket

    this.setStorage(multerS3({
      s3: this.s3,
      acl,
      bucket,
      contentType: contentType || multerS3.AUTO_CONTENT_TYPE,
      ...options,

      key: (req, file, cb) => {
        cb(null, this.getUniqueFilename(file.originalname))
      },

      metadata: (req, file, cb) => {
        // Store the determined width and height as meta-data on the s3 object
        // as well. You never know, it may become useful :)
        const { width, height } = file
        if (width != null || height != null) {
          cb(null, {
            width: `${width}`,
            height: `${height}`
          })
        } else {
github argos-ci / argos / src / server / routes / api.js View on Github external
import { formatUrlFromBuild } from 'modules/urls/buildUrl'
import Build from 'server/models/Build'
import Repository from 'server/models/Repository'
import ScreenshotBucket from 'server/models/ScreenshotBucket'
import buildJob from 'server/jobs/build'
import errorHandler from 'server/middlewares/errorHandler'

const router = new express.Router()
const s3 = new S3({
  signatureVersion: 'v4',
})
const upload = multer({
  storage: multerS3({
    s3,
    bucket: config.get('s3.screenshotsBucket'),
    contentType: multerS3.AUTO_CONTENT_TYPE,
  }),
})

/**
 * Takes a route handling function and returns
 * a function that wraps it in a `try/catch`. Caught
 * exceptions are forwarded to the `next` handler.
 */
export function errorChecking(routeHandler) {
  return async (req, res, next) => {
    try {
      await routeHandler(req, res, next)
    } catch (err) {
      // Handle objection errors
      const candidates = [err.status, err.statusCode, err.code, 500]
      err.status = candidates.find(Number.isInteger)
github minhuyen / generator-expressjs-rest / generators / app / templates / backend / src / services / s3.js View on Github external
import multer from 'multer';
import multerS3 from 'multer-s3';
import aws from 'aws-sdk';

import config from '../config';

const s3 = new aws.S3({
  accessKeyId: config.aws.accessKeyId,
  secretAccessKey: config.aws.secretAccessKey
});

const s3Storage = multerS3({
  s3: s3,
  bucket: config.aws.bucketName,
  acl: 'public-read',
  contentType: multerS3.AUTO_CONTENT_TYPE,
  metadata: function(req, file, cb) {
    cb(null, { fieldName: file.fieldname });
  },
  key: function(req, file, cb) {
    crypto.pseudoRandomBytes(16, function(err, raw) {
      cb(
        null,
        raw.toString('hex') + Date.now() + '.' + mime.extension(file.mimetype)
      );
    });
  }
});

const localStorage = multer.diskStorage({
  destination: function(req, file, callback) {
    const uploadFolder = path.join(__dirname, '..', '..', 'uploads');
github serranoarevalo / wetube / utils / fileUpload.js View on Github external
import multerS3 from "multer-s3";
import aws from "aws-sdk";

const s3 = new aws.S3({
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
  accessKeyId: process.env.AWS_KEY_ID
});

const ACL = "public-read";

export const avatarUpload = multer({
  storage: multerS3({
    s3,
    acl: ACL,
    bucket: "wetube/avatars",
    contentType: multerS3.AUTO_CONTENT_TYPE
  })
});

export const videoUpload = multer({
  storage: multerS3({
    s3,
    acl: ACL,
    bucket: "wetube/videos",
    contentType: (req, file, cb) => cb(null, "video/webm")
  })
});

multer-s3

Streaming multer storage engine for AWS S3

MIT
Latest version published 2 years ago

Package Health Score

59 / 100
Full package analysis

Popular multer-s3 functions