Trouble using blob store API

I’m trying to use the blob store API from an edge function using NextJS, but any call I make to getStore fails with this error when I run my site using netlify dev:

⨯ MissingBlobsEnvironmentError: The environment has not been configured to use Netlify Blobs. To use it manually, supply the following properties when creating a store: siteID, token

It’s not clear where I’m supposed to get a token, and the fact that I need one at all seems kind of suspicious since the blobs page doesn’t say anything about needing a token or site ID.

My site name is spelling-bee-helper, but I haven’t uploaded any of my test code yet.

Have you trie using netlify link to link your CLI to a site?

I had a site linked and it didn’t work. I couldn’t find any option in the site settings to enable blobs.

Did you ever mange to fix this?

I’ve been trying to get blobs working with a site I’ve deployed to Netlify, but when using the following syntax:

const store = getStore('foo');

and got exactly the same issue: MissingBlobsEnvironmentError: The environment has not been configured to use Netlify Blobs. To use it manually, supply the following properties when creating a store: siteID, token

and now, when I’ve changed it to:

const store = getStore({ siteID: 'MY_SITE_ID', token: 'foo', name: 'foo' });

I get the following issue: Error: Netlify Blobs has generated an internal error: 401 response

I don’t understand what I’m doing wrong, as the docs suggest that the first code snippet should work?

@hrishikesh - any help would be much appreciated

The first snipper only works in Functions API v2 and Edge Functions and only when you’re linked the site to the CLI. If either of that is false, you might have to resort to: netlify/blobs: A TypeScript client for Netlify Blobs (github.com)

Thanks @hrishikesh. I have changed my functions to use the v2 syntax, but now I note that:

export default async (req: Request, ctx: Context) => {
   return new Response(JSON.stringify(req));
}

will return an {} (i.e. empty object), even if I make a GET request with headers.

Do you know why that may be?

Why are you trying to return the Request? Request is not a JSON that you can just stringify. It’s a constructor: Request: Request() constructor - Web APIs | MDN (mozilla.org)

I also had a site linked via the netlify cli and blobs didn’t work. This is pretty confusing honestly. Do I have to manually inject the environment variables?

@hrishikesh do you have any tips on this?

Hi @_t_o_m did you ever figure out what your issue was? I have the same problem where I get that 401 error after explicitly supplying the siteid and token?

Without any details of your project, there’s not much help I can offer here.

1 Like

Hey fyi I believe I found out what the issue was for anyone else struggling with this who lands on the page - I believe it’s this issue from the blobs github repo.

Blobs don’t work unless they are inside of the request handler.

I’ve commented there.

Hi, I encountered the same problem and realized I do not get the problem if I use a default export instead of a named export. There are many examples of how to write a handler that vary. If i use

export const handler = async (req, context) => {
  const store = getStore('names');
}

I will get the MissingBlobsEnvironmentError.

If I use

export default async function handler(req, context) {
  const store = getStore('names');
}

everything works as expected.

Hope this helps someone!!

1 Like

This is expected. export handler is Functions v1 which doesn’t support Blobs out of the box. export default is Functions v2.