
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
This is a convenient wrapper around multer and google cloud storage API as a single express middleware to upload file from user to Google Cloud Storage.
It will change the field for the uploaded file with a url string like http://storage.googleapis.com/`bucket-name`/`filename` that you can save in database.
npm install gcs-upload
options:
It will return an upload object that have 3 methods: (.single(), .array(), and .fields()). You can use all of them just like how you would use multer.
note:
Instead of providing keyFilename in config, you can also use
GOOGLE_APPLICATION_CREDENTIALS
environment variable to store absolute path to the credential file.
Don't forget the enctype="multipart/form-data" in your form.
<form action="/upload-single" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
</form>
const express = require('express')
const gcsUpload = require('gcs-upload')
const app = express()
// .......
const upload = gcsUpload({
limits: {
fileSize: 1e6 // in bytes
},
gcsConfig: {
keyFilename: '/Users/me/google-credential-keyfile.json', // this can also be set using GOOGLE_APPLICATION_CREDENTIALS environment variable
bucketName: 'my-bucket',
prefix: () => `${Date.now()}-` // optional, this is it's default value
}
})
app.post('/upload-single', upload.single('file'), (req, res) => {
console.log(req.body)
res.end()
})
app.post('/upload-array', upload.array('files'), (req, res) => {
console.log(req.body)
res.end()
})
app.post('/upload-fields',
upload.fields([{ name: 'file1' }, { name: 'file2' }]),
(req, res) => {
console.log(req.body)
res.end()
}
)
// .......
To make uploaded files available for public view, add Storage Object Viewer
role for allUsers. Step by step instruction can be found here
FAQs
Express middleware to upload file to google cloud storage.
The npm package gcs-upload receives a total of 56 weekly downloads. As such, gcs-upload popularity was classified as not popular.
We found that gcs-upload demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.