
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
@netlify/blobs
Advanced tools
A JavaScript client for the Netlify Blob Store.
You can install @netlify/blobs
via npm:
npm install @netlify/blobs
To use the blob store, import the module and create an instance of the Blobs
class. The constructor accepts an object
with the following properties:
Property | Description | Required |
---|---|---|
authentication | An object containing authentication credentials (see Authentication) | Yes |
siteID | The Netlify site ID | Yes |
context | The deploy context to use (defaults to production ) | No |
fetcher | An implementation of a fetch-compatible module for making HTTP requests (defaults to globalThis.fetch ) | No |
import assert from 'node:assert'
import { Blobs } from '@netlify/blobs'
const store = new Blobs({
authentication: {
token: 'YOUR_NETLIFY_AUTH_TOKEN',
},
siteID: 'YOUR_NETLIFY_SITE_ID',
})
await store.set('some-key', 'Hello!')
const item = await store.get('some-key')
assert.strictEqual(item, 'Hello!')
Authentication with the blob storage is done in one of two ways:
Using a Netlify API token
import { Blobs } from '@netlify/blobs'
const store = new Blobs({
authentication: {
token: 'YOUR_NETLIFY_API_TOKEN',
},
siteID: 'YOUR_NETLIFY_SITE_ID',
})
Using a context object injected in Netlify Functions
import { Blobs } from '@netlify/blobs'
import type { Handler, HandlerEvent, HandlerContext } from '@netlify/functions'
export const handler: Handler = async (event: HandlerEvent, context: HandlerContext) => {
const store = new Blobs({
authentication: {
contextURL: context.blobs.url,
token: context.blobs.token,
},
siteID: 'YOUR_NETLIFY_SITE_ID',
})
}
get(key: string, { type: string }): Promise<any>
Retrieves an object with the given key.
Depending on the most convenient format for you to access the value, you may choose to supply a type
property as a
second parameter, with one of the following values:
arrayBuffer
: Returns the entry as an
ArrayBuffer
blob
: Returns the entry as a Blob
json
: Parses the entry as JSON and returns the resulting objectstream
: Returns the entry as a ReadableStream
text
(default): Returns the entry as a string of plain textIf an object with the given key is not found, null
is returned.
const entry = await blobs.get('some-key', { type: 'json' })
console.log(entry)
set(key: string, value: ArrayBuffer | Blob | ReadableStream | string): Promise<void>
Creates an object with the given key and value.
If an entry with the given key already exists, its value is overwritten.
await blobs.set('some-key', 'This is a string value')
setJSON(key: string, value: any): Promise<void>
Convenience method for creating a JSON-serialized object with the given key.
If an entry with the given key already exists, its value is overwritten.
await blobs.setJSON('some-key', {
foo: 'bar',
})
delete(key: string): Promise<void>
Deletes an object with the given key, if one exists.
await blobs.delete('my-key')
Contributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.
Netlify Blobs is open-source software licensed under the MIT license.
FAQs
TypeScript client for Netlify Blobs
The npm package @netlify/blobs receives a total of 758,715 weekly downloads. As such, @netlify/blobs popularity was classified as popular.
We found that @netlify/blobs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 16 open source maintainers 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
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.