1.0.0-develop.1 • Published 3 years ago

multer-gcs-storage v1.0.0-develop.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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:

KeyDescriptionNote
sizeSize of the file in bytes
bucketThe bucket used to store the fileMulterGCSStorage
keyThe name of the fileMulterGCSStorage
aclAccess control for the fileMulterGCSStorage
contentTypeThe mimetype used to upload the fileMulterGCSStorage
metadataThe metadata object to be sent to MinioMulterGCSStorage
locationThe Minio url to access the fileMulterGCSStorage
etagThe etagof the uploaded file in MinioMulterGCSStorage
contentDispositionThe contentDisposition used to upload the fileMulterGCSStorage
storageClassThe storageClass to be used for the uploaded file in MinioMulterGCSStorage
versionIdThe 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