Gathering detailed insights and metrics for multer-cloud-storage
Gathering detailed insights and metrics for multer-cloud-storage
Gathering detailed insights and metrics for multer-cloud-storage
Gathering detailed insights and metrics for multer-cloud-storage
npm install multer-cloud-storage
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
35 Stars
86 Commits
23 Forks
4 Watching
1 Branches
1 Contributors
Updated on 20 Apr 2024
TypeScript (99.06%)
JavaScript (0.94%)
Cumulative downloads
Total Downloads
Last day
-4.2%
619
Compared to previous day
Last week
1.5%
3,843
Compared to previous week
Last month
18.9%
17,215
Compared to previous month
Last year
51%
165,201
Compared to previous year
multer-cloud-storage is a multer custom store engine for Google Cloud Storage service. It is a fork from ARozar's multer-google-storage that uses latest version of Google Cloud's API, allows additional information (like destination and contentType) to be set and reduces module footprint.
npm install multer-cloud-storage --save
or
yarn add multer-cloud-storage
import * as multer from 'multer';
import * as express from 'express';
import MulterGoogleCloudStorage from 'multer-cloud-storage';
const app = express();
const uploadHandler = multer({
storage: new MulterGoogleCloudStorage()
});
app.post('/upload', uploadHandler.any(), (req, res) => {
console.log(req.files);
res.json(req.files);
});
var multer = require("multer");
var express = require("express");
var multerGoogleStorage = require("multer-cloud-storage");
var app = express();
var uploadHandler = multer({
storage: multerGoogleStorage.storageEngine()
});
app.post('/upload', uploadHandler.any(), function (req, res) {
console.log(req.files);
res.json(req.files);
});
NB: This package is written to work with es5 or higher. If you have an editor or IDE that can understand d.ts (typescript) type definitions you will get additional support from your tooling though you do not need to be using typescript to use this package.
For instructions on how to create a storage bucket see the following documentation from Google.
For instructions on how to obtain the JSON keyfile as well a projectId (contained in the key file) please refer to the following documentation from Google.
If using the MulterGoogleCloudStorage class without passing in any configuration options then the following environment variables will need to be set:
The constructor of the MulterGoogleCloudStorage class can be passed an optional configuration object.
Parameter Name | Type | Sample Value | Default Value | Notes |
---|---|---|---|---|
acl | string | "publicRead" | "private" | Accepted values are defined in predefinedAcl options |
autoRetry | boolean | true | true | |
bucket | string | "mybucketname" | Takes precedence over GCS_BUCKET | |
contentType | function | (request, file): string | ||
contentType | string | "application/pdf" | If set, this value will be used in place of file.mimetype | |
destination | string | "my_folder/" | "" | Despite Google Cloud Storage service stores objects in a flat name space, it is possible to list and filter them in a tree-like structure (more on How Subdirectories Work article) |
email | string | "test@test.com" | ||
filename | function | (request, file, callback): void | ||
filename | string | "my_file.pdf" | If defined, this name will be used in place of file.originalname - use with caution, because the object can be easily overwritten (consider to configure Object Versioning and Concurrency Control) | |
hideFilename | boolean | true | false | If set to true, an UUID v4 will be used as object filename and Content-Type will be undefined |
keyFilename | string | "./key.json" | Takes precedence over GCS_KEYFILE | |
maxRetries | number | 5 | 3 | |
projectId | string | "test-prj-1234" | Takes precedence over GCLOUD_PROJECT | |
uniformBucketLevelAccess | boolean | true | Signifies whether uniformBucketLevelAccess is enabled on the target bucket. When true , the predefinedAcl parameter is removed from requests as it causes 400 Bad Request responses. |
If you need to customize the naming of files then you are able to provide a function that will be called before uploading the file. The third argument of the function must be a standard node callback so pass any error in the first argument (or null on sucess) and the string name of the file on success.
getFilename(req, file, cb) {
cb(null,`${file.originalname}`);
}
If you need to customize the content-type of files then you are able to provide a function that will be called before uploading the file.
getContentType( req, file ) {
return undefined;
}
When used with multer-cloud-storage, multer will present additional file information.
Each file contains the following information:
Key | Description | Origin |
---|---|---|
fieldname | Field name specified in the form | multer |
originalname | Name of the file on the user's computer | multer |
encoding | Encoding type of the file | multer |
mimetype | Mime type of the file | multer |
bucket | Bucket name | multer-cloud-storage |
destination | The pseudo-folder to which the file has been saved | multer-cloud-storage |
filename | The name of the file on Google Cloud Storage | multer-cloud-storage |
path | The full path to the uploaded file (basically destination + filename ) | multer-cloud-storage |
contentType | Content-type defined for stored object | multer-cloud-storage |
size | Size of the file in bytes | multer-cloud-storage |
uri | Google Cloud Storage path | multer-cloud-storage |
linkUrl | Download link for allowed users (may require authentication) | multer-cloud-storage |
selfLink | The link to the stored object (used for Cloud Storage APIs requests) | multer-cloud-storage |
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
4 existing vulnerabilities detected
Details
Reason
Found 7/19 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More