Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore: added ephemeral storage guide (#30791)

Lakshan Perera36b6d85c7ea3
diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
index 96ad2af0b61..3f03268edb5 100644
--- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
+++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
@@ -1272,6 +1272,10 @@ export const functions: NavMenuConstant = {
name: 'Background Tasks',
url: '/guides/functions/background-tasks',
},
+ {
+ name: 'Ephemeral Storage',
+ url: '/guides/functions/ephemeral-storage',
+ },
{
name: 'Running AI Models',
url: '/guides/functions/ai-models',
diff --git a/apps/docs/content/guides/functions/ephemeral-storage.mdx b/apps/docs/content/guides/functions/ephemeral-storage.mdx
new file mode 100644
index 00000000000..acf9ebfcbab
--- /dev/null
+++ b/apps/docs/content/guides/functions/ephemeral-storage.mdx
@@ -0,0 +1,54 @@
+---
+id: 'function-ephemeral-storage'
+title: 'Ephemeral Storage'
+description: 'Read and write from temporary directory'
+subtitle: 'Read and write from temporary directory'
+---
+
+Edge Functions provides ephemeral file storage. You can read and write files to the `/tmp` directory.
+
+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.
+
+### Use cases
+
+Here are some use cases where ephemeral storage can be useful:
+
+- Unzip an archive of CSVs and then add them as records to the DB
+- Custom image manipulation workflows (using [MagickWasm](https://supabase.com/docs/guides/functions/examples/image-manipulation))
+
+You can use [Background Tasks](https://supabase.com/docs/guides/functions/background-tasks) to handle slow file processing outside of a request.
+
+### How to use
+
+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.
+
+### Example
+
+Here is an example of how to write a user-uploaded zip file into a temporary file for further processing.
+
+```js
+Deno.serve(async (req) => {
+ if (req.headers.get('content-type') !== 'application/zip') {
+ return new Response('file must be a zip file', {
+ status: 400,
+ })
+ }
+
+ const uploadId = crypto.randomUUID()
+ await Deno.writeFile('/tmp/' + uploadId, req.body)
+
+ // do something with the written zip file
+
+ return new Response('ok')
+})
+```
+
+### Unavailable APIs
+
+Currently, the synchronous APIs (eg: `Deno.writeFileSync` or `Deno.mkdirSync`) for creating or writing files are not supported.
+
+You can use sync variations of read APIs (eg: `Deno.readFileSync`).
+
+### Limits
+
+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.