Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
google-cloud-bucket
Advanced tools
Google Cloud Bucket is node.js package to add objects to a Google Cloud Bucket.
npm i google-cloud-bucket --save
Before using this package, you must first:
Have a Google Cloud Account.
Have a bucket in that Google Account.
Have a Service Account set up with the following 2 roles:
roles/storage.objectCreator
roles/storage.objectAdmin
(only if you want to update access to object)roles/storage.admin
(only if you want to update access to an entire bucket)Get the JSON keys file for that Service Account above
Save that JSON key into a service-account.json
file. Make sure it is located under a path that is accessible to your app (the root folder usually).
const { join } = require('path')
const { client } = require('google-cloud-bucket')
const storage = client.new({
jsonKeyFile: join(__dirname, './service-account.json')
})
const someObject = {
firstname: 'Nicolas',
lastname: 'Dao',
company: 'Neap Pty Ltd',
city: 'Sydney'
}
// ADDING AN OBJECT WITH PRIVATE ACCESS
storage.insert(someObject, 'your-bucket/a-path/filename.json') // insert an object into a bucket 'a-path/filename.json' does not need to exist
.then(() => storage.get('your-bucket/a-path/filename.json')) // retrieve that new object
.then(res => console.log(JSON.stringify(res, null, ' ')))
// ADDING A HTML PAGE WITH PUBLIC ACCESS (warning: Your service account must have the 'roles/storage.objectAdmin' role)
const html = `
<!doctype html>
<html>
<body>
<h1>Hello Giiiiirls</h1>
</body>
</html>`
storage.insert(html, 'your-bucket/a-path/index.html', { public: true })
.then(({ data:{ uri } }) => console.log(`Your web page is publicly available at: ${uri}`))
Notice the usage of the
public: true
flag in theinsert
statement above. This automatically makes this specific file publicly available at https://storage.googleapis.com/your-bucket/a-path/index.html. If that file is supposed to stay private, then don't use that flag. To make the entire bucket public, refer to the next section.
This allows to make any files publicly readable by anybody on the web. That's usefull if you want to host a website, or publish data (e.g., RSS feed).
// MAKING AN EXISTING OBJECT PUBLICLY READABLE (warning: Your service account must have the 'roles/storage.objectAdmin' role)
storage.addPublicAccess('your-bucket/a-path/private.html')
.then(({ data:{ uri } }) => console.log(`Your web page is publicly available at: ${uri}`))
// MAKING A BUCKET PUBLICLY READABLE (warning: Your service account must have the 'roles/storage.admin' role)
// Once a bucket is public, all content added to it (even when omitting the 'public' flag) is public
storage.addPublicAccess('your-bucket')
.then(({ data:{ uri } }) => console.log(`Your web page is publicly available at: ${uri}`))
// Alternatively you can also use this API:
storage.config('your-bucket').addPublicAccess()
.then(({ data:{ uri } }) => console.log(`Your web page is publicly available at: ${uri}`))
// REMOVE THE PUBLICLY READABLE ACCESS FROM A BUCKET (warning: Your service account must have the 'roles/storage.admin' role)
storage.removePublicAccess('your-bucket')
// or
storage.config('your-bucket').removePublicAccess()
If your files are publicly readable on the web, they might not be accessible when referenced from other websites. To enable other websites to access your files, you will have to configure CORS on your bucket:
// CONFIGURE CORS ON A BUCKET (warning: Your service account must have the 'roles/storage.admin' role)
storage.config('your-bucket').update({
cors:[{
origin: ['*'],
method: ['GET', 'OPTIONS', 'HEAD'],
responseHeader: ['Authorization', 'Origin', 'X-Requested-With', 'Content-Type', 'Accept'],
maxAgeSeconds: 3600
}]
}).then(() => `CORS successfully set up on your bucket.`)
We are Neap, an Australian Technology consultancy powering the startup ecosystem in Sydney. We simply love building Tech and also meeting new people, so don't hesitate to connect with us at https://neap.co.
Our other open-sourced projects:
Copyright (c) 2018, Neap Pty Ltd. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NEAP PTY LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0.3.1 (2018-12-05)
<a name="0.3.0"></a>
FAQs
Nodejs package to manage Google Cloud Buckets and its objects.
The npm package google-cloud-bucket receives a total of 117 weekly downloads. As such, google-cloud-bucket popularity was classified as not popular.
We found that google-cloud-bucket 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.