Ephemeral Storage
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)
You can use Background Tasks to handle slow file processing outside of a request.
How to use
You can use Deno File System APIs or the node:fs
module to access the /tmp
path.
Example
Here is an example of how to write a user-uploaded zip file into temporary storage for further processing.
_14Deno.serve(async (req) => {_14 if (req.headers.get('content-type') !== 'application/zip') {_14 return new Response('file must be a zip file', {_14 status: 400,_14 })_14 }_14_14 const uploadId = crypto.randomUUID()_14 await Deno.writeFile('/tmp/' + uploadId, req.body)_14_14 // do something with the written zip file_14_14 return new Response('ok')_14})
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.