> ## Documentation Index
> Fetch the complete documentation index at: https://confect.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Storage

> Store and retrieve blobs using Convex file storage.

Use the `Storage` service for file storage in queries, mutations, actions, and HTTP actions. Import it from your generated services module:

```ts theme={null}
import * as Effect from "effect/Effect";
import { Storage } from "./confect/_generated/services";

Effect.gen(function* () {
  const storage = yield* Storage;

  return yield* storage.getUrl(storageId);
});
```

The service is available in every context, but each operation retains Convex's context restrictions. Confect checks these requirements when you implement a function or middleware.

| Operation | Returns | Available in |
| - | - | - |
| `getUrl(storageId)` | `URL` | Queries, mutations, actions, and HTTP actions |
| `generateUploadUrl` | `URL` | Mutations, actions, and HTTP actions |
| `delete(storageId)` | `void` | Mutations, actions, and HTTP actions |
| `get(storageId)` | `Blob` | Mutations, actions, and HTTP actions |
| `store(blob, options?)` | `Id<"_storage">` | Mutations, actions, and HTTP actions |

Every operation returns an Effect. The table lists the value produced when it succeeds.

## Get a download URL

Query

Mutation

Action

HTTP Action

Retrieve a blob's download URL with `getUrl`. The result is a `URL` object, not a string. If the blob doesn't exist, the effect fails with `BlobNotFoundError`.

```ts theme={null}
Effect.gen(function* () {
  const storage = yield* Storage;
  return yield* storage.getUrl(storageId);
});
```

## Generate an upload URL

Mutation

Action

HTTP Action

Generate a URL that a client can use to upload a blob. `generateUploadUrl` is an Effect property, so yield it without parentheses. It produces a `URL` object.

```ts theme={null}
Effect.gen(function* () {
  const storage = yield* Storage;
  return yield* storage.generateUploadUrl;
});
```

## Delete a blob

Mutation

Action

HTTP Action

Delete a stored blob by its storage ID. If deletion fails, the effect fails with `BlobNotFoundError`.

```ts theme={null}
Effect.gen(function* () {
  const storage = yield* Storage;
  yield* storage.delete(storageId);
});
```

## Get a blob

Mutation

Action

HTTP Action

Read a stored file directly as a `Blob`. If the blob doesn't exist, the effect fails with `BlobNotFoundError`.

```ts theme={null}
Effect.gen(function* () {
  const storage = yield* Storage;
  return yield* storage.get(storageId);
});
```

## Store a blob

Mutation

Action

HTTP Action

Store a `Blob` directly and receive its storage ID. Optionally supply a SHA-256 hash in `options` for Convex to verify.

```ts theme={null}
Effect.gen(function* () {
  const storage = yield* Storage;
  return yield* storage.store(blob);
});
```

```ts theme={null}
Effect.gen(function* () {
  const storage = yield* Storage;
  return yield* storage.store(blob, { sha256: expectedHash });
});
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.