multer-gcs-storage
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-develop.1 • Public • Published

Multer GCS (Google cloud storage) Storage

GCS storage for Multer.

Installation

npm install --save multer-gcs-storage

Usage

import { Storage } from "@google-cloud/storage";
import express from 'express';
import multer from 'multer';
import multerGCSStorage from 'multer-minio-storage';

const app = express();
const storageClient = new Storage({ projectId: config.gc.projectId, keyFilename: config.gc.keyFilename });

const upload = multer({
  storage: multerGCSStorage({
    gcsClient: storageClient,
    bucket: 'some-bucket',
    metadata: function (req, file, cb) {
      cb(null, {fieldName: file.fieldname});
    },
    key: function (req, file, cb) {
      cb(null, Date.now().toString())
    }
  })
})

app.post('/upload', upload.array('photos', 3), function(req, res, next) {
  res.send('Successfully uploaded ' + req.files.length + ' files!')
})

File information

Each file contains the following information exposed by multer-gcs-storage:

Key Description Note
size Size of the file in bytes
bucket The bucket used to store the file MulterGCSStorage
key The name of the file MulterGCSStorage
acl Access control for the file MulterGCSStorage
contentType The mimetype used to upload the file MulterGCSStorage
metadata The metadata object to be sent to Minio MulterGCSStorage
location The Minio url to access the file MulterGCSStorage
etag The etagof the uploaded file in Minio MulterGCSStorage
contentDisposition The contentDisposition used to upload the file MulterGCSStorage
storageClass The storageClass to be used for the uploaded file in Minio MulterGCSStorage
versionId The versionId is an optional param returned by Minio for versioned buckets. MulterGCSStorage

Testing

The tests mock all access to S3 and can be run completely offline.

npm test

Readme

Keywords

Package Sidebar

Install

npm i multer-gcs-storage

Weekly Downloads

7

Version

1.0.0-develop.1

License

MIT

Unpacked Size

24.9 kB

Total Files

17

Last publish

Collaborators

  • hoangnguyen1247