In-memory

A very simple in-memory filesystem is available which is only accessible via HTTP under /memfs. Use the POST or PUT method with the path to that file. The body of the request contains the contents of the file. No particular encoding or Content-Type is required. The file can then be downloaded from the same path.

This filesystem is practical for often changing data (e.g. HLS live stream) in order not to stress the disk or to wear out a flash drive. Also you don't need to setup a RAM drive or similar on your system.

curl http://127.0.0.1:8080/memfs/path/to/a/file.txt -X PUT -d @somefile.txt

The returned Content-Type is based solely on the file extension. For a list of known mime-types and their extensions see storage.mime_types in the configuration.

Access protection

It is strongly recommended to enable a username/password (HTTP Basic-Auth) protection for any PUT/POST and DELETE operations on /memfs. GET operations are not protected.

In-memory

By default HTTP Basic-Auth is enabled with the username "admin" and a random password.

Fetch a file from the memory filesystem

get

Fetch a file from the memory filesystem

Path parameters
pathstringRequired

Path to file

Responses
200
OK
Responsestring
get
GET /{path} HTTP/1.1
Host: memfs
Accept: */*
text

Add a file to the memory filesystem

put

Writes or overwrites a file on the memory filesystem

Authorizations
Path parameters
pathstringRequired

Path to file

Body
integer[]Optional
Responses
201
Created
Responsestring
put
PUT /{path} HTTP/1.1
Host: memfs
Authorization: Basic username:password
Content-Type: application/data
Accept: */*
Content-Length: 3

[
  1
]
text

Remove a file from the memory filesystem

delete

Remove a file from the memory filesystem

Authorizations
Path parameters
pathstringRequired

Path to file

Responses
200
OK
text/plain
Responsestring
delete
DELETE /{path} HTTP/1.1
Host: memfs
Authorization: Basic username:password
Accept: */*
text

Example:

Use these endpoints to, e.g., store HLS chunks and .m3u8 files (in contrast to an actual disk or a ramdisk):

ffmpeg -f lavfi -re -i testsrc2=size=640x480:rate=25 -c:v libx264 -preset:v ultrafast -r 25 -g 50 -f hls -start_number 0 -hls_time 2 -hls_list_size 6 -hls_flags delete_segments+temp_file+append_list -method PUT -hls_segment_filename http://127.0.0.1:8080/memfs/foobar_%04d.ts -y http://127.0.0.1:8080/memfs/foobar.m3u8

Then you can play it generally with, e.g., ffplay http://127.0.0.1:8080/memfs/foobar.m3u8.

API

The contents of the /memfs are also accessible via the API in the same way as described above, but with the same protection as the API (see API-Security configuration) for all operations. It is also possible to list all files that are currently in the filesystem.

Create, Update

Example:

echo 'test' > example.txt && \
curl http://127.0.0.1:8080/api/v3/fs/mem/example.txt \
   -d @example.txt \
   -X PUT

After the successful upload the file is available at /memfs/example.txt and /api/v3/fs/mem/example.txt.

Description:

Add a file to the memory filesystem

put

Writes or overwrites a file on the memory filesystem

Authorizations
Path parameters
pathstringRequired

Path to file

Body
integer[]Optional
Responses
201
Created
Responsestring
put
PUT /v3/fs/mem/{path} HTTP/1.1
Host: api
Authorization: YOUR_API_KEY
Content-Type: application/data
Accept: */*
Content-Length: 3

[
  1
]
text

Read

List all files

Listing all currently stored files is done by calling /api/v3/fs/mem. It also accepts the query parameters pattern, sort (name, size, or lastmod) and order (asc or desc). If none of the parameters are given, all files will be listed sorted by their last modification time in ascending order.

With the pattern parameter you can filter the list based on a glob pattern, with the addition of the ** placeholder to include multiple subdirectories, e.g. listing all .ts file in the root directory has the pattern /*.ts, listing all .ts file in the whole filesystem has the pattern /**.ts.

Example:

curl "http://127.0.0.1:8080/api/v3/fs/mem?sort=name&order=asc" \
   -X GET

Description:

List all files on the memory filesystem

get

List all files on the memory filesystem. The listing can be ordered by name, size, or date of last modification in ascending or descending order.

Authorizations
Query parameters
globstringOptional

glob pattern for file names

sortstringOptional

none, name, size, lastmod

orderstringOptional

asc, desc

Responses
200
OK
application/json
get
GET /v3/fs/mem HTTP/1.1
Host: api
Authorization: YOUR_API_KEY
Accept: */*
200

OK

[
  {
    "last_modified": 1,
    "name": "text",
    "size_bytes": 1
  }
]

Download a file

For downloading a file you have to specify the complete path and filename. The Content-Type will always be application/data.

Example:

curl http://127.0.0.1:8080/api/v3/fs/mem/example.txt \
   -X GET

Description:

Fetch a file from the memory filesystem

get

Fetch a file from the memory filesystem

Authorizations
Path parameters
pathstringRequired

Path to file

Responses
200
OK
Responsestring
get
GET /v3/fs/mem/{path} HTTP/1.1
Host: api
Authorization: YOUR_API_KEY
Accept: */*
text

Linking a file will return a redirect to the linked file. The target of the redirect has to be in the body of the request.

Example:

curl http://127.0.0.1:8080/api/v3/fs/mem/example2.txt \
   -d 'example.txt'
   -X PATCH

Description:

Create a link to a file in the memory filesystem

patch

Create a link to a file in the memory filesystem. The file linked to has to exist.

Authorizations
Path parameters
pathstringRequired

Path to file

Body
stringOptional
Responses
201
Created
Responsestring
patch
PATCH /v3/fs/mem/{path} HTTP/1.1
Host: api
Authorization: YOUR_API_KEY
Content-Type: application/data
Accept: */*
Content-Length: 6

"text"
text

Delete

For deleting a file you have to specify the complete path and filename.

Example:

curl http://127.0.0.1:8080/api/v3/fs/mem/example.txt \
   -X DELETE

Description:

Remove a file from the memory filesystem

delete

Remove a file from the memory filesystem

Authorizations
Path parameters
pathstringRequired

Path to file

Responses
200
OK
text/plain
Responsestring
delete
DELETE /v3/fs/mem/{path} HTTP/1.1
Host: api
Authorization: YOUR_API_KEY
Accept: */*
text

Configuration

In-memory

Last updated

Was this helpful?