Skip to content

Commit 36b6d85

Browse files
laktekcharislam
andauthored
chore: added ephemeral storage guide (supabase#30791)
* chore: added ephemeral storage guide * add use cases section * remove word * Apply suggestions from code review Co-authored-by: Charis <[email protected]> * prettier --------- Co-authored-by: Charis <[email protected]>
1 parent 64531ac commit 36b6d85

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,10 @@ export const functions: NavMenuConstant = {
12721272
name: 'Background Tasks',
12731273
url: '/guides/functions/background-tasks',
12741274
},
1275+
{
1276+
name: 'Ephemeral Storage',
1277+
url: '/guides/functions/ephemeral-storage',
1278+
},
12751279
{
12761280
name: 'Running AI Models',
12771281
url: '/guides/functions/ai-models',
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
id: 'function-ephemeral-storage'
3+
title: 'Ephemeral Storage'
4+
description: 'Read and write from temporary directory'
5+
subtitle: 'Read and write from temporary directory'
6+
---
7+
8+
Edge Functions provides ephemeral file storage. You can read and write files to the `/tmp` directory.
9+
10+
Ephemeral storage will reset on each function invocation. This means the files you write during an invocation can only be read within the same invocation.
11+
12+
### Use cases
13+
14+
Here are some use cases where ephemeral storage can be useful:
15+
16+
- Unzip an archive of CSVs and then add them as records to the DB
17+
- Custom image manipulation workflows (using [MagickWasm](https://supabase.com/docs/guides/functions/examples/image-manipulation))
18+
19+
You can use [Background Tasks](https://supabase.com/docs/guides/functions/background-tasks) to handle slow file processing outside of a request.
20+
21+
### How to use
22+
23+
You can use [Deno File System APIs](https://docs.deno.com/api/deno/file-system) or the [`node:fs` module](https://docs.deno.com/api/node/fs/) to access the `/tmp` path.
24+
25+
### Example
26+
27+
Here is an example of how to write a user-uploaded zip file into a temporary file for further processing.
28+
29+
```js
30+
Deno.serve(async (req) => {
31+
if (req.headers.get('content-type') !== 'application/zip') {
32+
return new Response('file must be a zip file', {
33+
status: 400,
34+
})
35+
}
36+
37+
const uploadId = crypto.randomUUID()
38+
await Deno.writeFile('/tmp/' + uploadId, req.body)
39+
40+
// do something with the written zip file
41+
42+
return new Response('ok')
43+
})
44+
```
45+
46+
### Unavailable APIs
47+
48+
Currently, the synchronous APIs (eg: `Deno.writeFileSync` or `Deno.mkdirSync`) for creating or writing files are not supported.
49+
50+
You can use sync variations of read APIs (eg: `Deno.readFileSync`).
51+
52+
### Limits
53+
54+
In the hosted platform, a free project can write up to 256MB of data to ephemeral storage. A paid project can write up to 512MB.

0 commit comments

Comments
 (0)