
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
This is a simple 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 it just like how you would use multer.
Don't forget the enctype="multipart/form-data" in your form.
<form action="/uploadSingle" 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/keyfile.json',
bucketName: 'myBucket'
}
})
app.post('/uploadSingle', upload.single('file'), (req, res) => {
console.log(req.body)
res.end()
})
app.post('/uploadArray', upload.array('files'), (req, res) => {
console.log(req.body)
res.end()
})
app.post('/uploadFields',
upload.fields([{ name: 'file1' }, { name: 'file2' }]),
(req, res) => {
console.log(req.body)
res.end()
}
)
// .......
FAQs
Express middleware to upload file to google cloud storage.
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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.