@@ -23,6 +23,34 @@ To start reading and writing data, you must first get a reference to a store usi
2323
2424This method takes an options object that lets you configure the store for different access modes.
2525
26+ ### Environment-based configuration
27+
28+ Rather than explicitly passing the configuration context to the ` getStore ` method, it can be read from the execution
29+ environment. This is particularly useful for setups where the configuration data is held by one system and the data
30+ needs to be accessed in another system, with no direct communication between the two.
31+
32+ To do this, the system that holds the configuration data should set a global variable called ` netlifyBlobsContext ` or an
33+ environment variable called ` NETLIFY_BLOBS_CONTEXT ` with a Base64-encoded, JSON-stringified representation of an object
34+ with the following properties:
35+
36+ - ` apiURL ` (optional) or ` edgeURL ` : URL of the Netlify API (for [ API access] ( #api-access ) ) or the edge endpoint (for
37+ [ Edge access] ( #edge-access ) )
38+ - ` token ` : Access token for the corresponding access mode
39+ - ` siteID ` : ID of the Netlify site
40+
41+ This data is automatically populated by Netlify in the execution environment for both serverless and edge functions.
42+
43+ With this in place, the ` getStore ` method can be called just with the store name. No configuration object is required,
44+ since it'll be read from the environment.
45+
46+ ``` ts
47+ import { getStore } from ' @netlify/blobs'
48+
49+ const store = getStore (' my-store' )
50+
51+ console .log (await store .get (' my-key' ))
52+ ```
53+
2654### API access
2755
2856You can interact with the blob store through the [ Netlify API] ( https://docs.netlify.com/api/get-started ) . This is the
@@ -59,8 +87,7 @@ Create a store for edge access by calling `getStore` with the following paramete
5987
6088- ` name ` (string): Name of the store
6189- ` siteID ` (string): ID of the Netlify site
62- - ` token ` (string): [ Personal access token] ( https://docs.netlify.com/api/get-started/#authentication ) to access the
63- Netlify API
90+ - ` token ` (string): Access token to the edge endpoint
6491- ` edgeURL ` (string): URL of the edge endpoint
6592
6693``` ts
@@ -69,8 +96,8 @@ import { Buffer } from 'node:buffer'
6996import { getStore } from ' @netlify/blobs'
7097
7198// Serverless function using the Lambda compatibility mode
72- export const handler = async (event , context ) => {
73- const rawData = Buffer .from (context . clientContext . custom .blobs , ' base64' )
99+ export const handler = async (event ) => {
100+ const rawData = Buffer .from (event .blobs , ' base64' )
74101 const data = JSON .parse (rawData .toString (' ascii' ))
75102 const store = getStore ({
76103 edgeURL: data .url ,
@@ -87,34 +114,6 @@ export const handler = async (event, context) => {
87114}
88115```
89116
90- ### Environment-based configuration
91-
92- Rather than explicitly passing the configuration context to the ` getStore ` method, it can be read from the execution
93- environment. This is particularly useful for setups where the configuration data is held by one system and the data
94- needs to be accessed in another system, with no direct communication between the two.
95-
96- To do this, the system that holds the configuration data should set a global variable called ` netlifyBlobsContext ` or an
97- environment variable called ` NETLIFY_BLOBS_CONTEXT ` with a Base64-encoded, JSON-stringified representation of an object
98- with the following properties:
99-
100- - ` apiURL ` (optional) or ` edgeURL ` : URL of the Netlify API (for [ API access] ( #api-access ) ) or the edge endpoint (for
101- [ Edge access] ( #edge-access ) )
102- - ` token ` : Access token for the corresponding access mode
103- - ` siteID ` : ID of the Netlify site
104-
105- This data is automatically populated by Netlify in the execution environment for both serverless and edge functions.
106-
107- With this in place, the ` getStore ` method can be called just with the store name. No configuration object is required,
108- since it'll be read from the environment.
109-
110- ``` ts
111- import { getStore } from ' @netlify/blobs'
112-
113- const store = getStore (' my-store' )
114-
115- console .log (await store .get (' my-key' ))
116- ```
117-
118117### Deploy scope
119118
120119By default, stores exist at the site level, which means that data can be read and written across different deploys and
0 commit comments