# Disk

The disk filesystem gives access to the actual directory that has been provided in the configuration as [storage.disk.dir](https://docs.datarhei.com/core/configuration/storage#disk). It accessible only for retrieval via HTTP under /.

{% tabs %}
{% tab title=" GET" %}

```
curl http://127.0.0.1:8080/path/to/a/file.txt -o file.txt
```

{% endtab %}
{% endtabs %}

Given that the requested file exists, 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](https://docs.datarhei.com/core/configuration/storage#mime-types) in the configuration.

## Access

{% openapi src="<https://demo.datarhei.com/api/swagger/doc.json>" path="/{path}" method="get" %}
<https://demo.datarhei.com/api/swagger/doc.json>
{% endopenapi %}

## API

The contents of the disk filesystem at / 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](https://docs.datarhei.com/core/configuration/api-security#auth)) for all operations. It is also possible to list all files that are currently in the filesystem.

### Create, Update

Example:

{% tabs %}
{% tab title="Curl" %}

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

{% endtab %}

{% tab title="PyClient" %}

```python
from core_client import Client

client = Client(base_url="http://127.0.0.1:8080")
client.login()

client.v3_fs_put_file(
    name: "disk",
    path: "example.txt",
    data: b"test"
)
```

{% hint style="info" %}
**Path** is the complete file path incl. file name (/a/b/c/1.txt).
{% endhint %}
{% endtab %}

{% tab title="GoClient" %}

```go
import (
    "strings"
    "github.com/datarhei/core-client-go/v16"
)

client, _ := coreclient.New(coreclient.Config{
    Address: "https://127.0.0.1:8080",
})

data := strings.NewReader("test")
err := client.FilesystemAddFile("disk", "/example.txt", data)
```

The contents for the upload has to be provided as an `io.Reader`.
{% endtab %}
{% endtabs %}

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

Description:

{% openapi src="<https://demo.datarhei.com/api/swagger/doc.json>" path="/api/v3/fs/disk/{path}" method="put" %}
<https://demo.datarhei.com/api/swagger/doc.json>
{% endopenapi %}

### Read

#### List all files

Listing all currently stored files is done by calling `/api/v3/fs/disk`. 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](https://en.wikipedia.org/wiki/Glob_\(programming\)), 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:

{% tabs %}
{% tab title="Curl" %}

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

{% endtab %}

{% tab title="PyClient" %}

```python
from core_client import Client

client = Client(base_url="http://127.0.0.1:8080")
client.login()

core_memfs_list = client.v3_fs_get_file_list(name="disk")
print(core_memfs_list)
```

{% endtab %}

{% tab title="GoClient" %}

```go
import (
    "fmt"
    "github.com/datarhei/core-client-go/v16"
)

client, _ := coreclient.New(coreclient.Config{
    Address: "https://127.0.0.1:8080",
})

files, err := client.FilesystemList("disk", "/*.", coreclient.SORT_NAME, coreclient.ORDER_ASC)

for _, file := range files {
    fmt.Printf("%+v\n", file)
}
```

{% endtab %}
{% endtabs %}

Description:

{% openapi src="<https://demo.datarhei.com/api/swagger/doc.json>" path="/api/v3/fs/disk" method="get" %}
<https://demo.datarhei.com/api/swagger/doc.json>
{% endopenapi %}

#### 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:

{% tabs %}
{% tab title="Curl" %}

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

{% endtab %}

{% tab title="PyClient" %}

```python
from core_client import Client

client = Client(base_url="http://127.0.0.1:8080")
client.login()

core_memfs_file = client.v3_fs_get_file(
    name="disk",
    path="example.txt"
)
print(core_memfs_file)
```

{% endtab %}

{% tab title="GoClient" %}

```go
import (
    "github.com/datarhei/core-client-go/v16"
)

client, _ := coreclient.New(coreclient.Config{
    Address: "https://127.0.0.1:8080",
})

data, err := client.FilesystemGetFile("disk", "/example.txt")
defer data.Close()
```

The returned data is an `io.ReadCloser`.
{% endtab %}
{% endtabs %}

Description:

{% openapi src="<https://demo.datarhei.com/api/swagger/doc.json>" path="/api/v3/fs/disk/{path}" method="get" %}
<https://demo.datarhei.com/api/swagger/doc.json>
{% endopenapi %}

### Delete

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

Example:

{% tabs %}
{% tab title="Curl" %}

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

{% endtab %}

{% tab title="PyClient" %}

```python
from core_client import Client

client = Client(base_url="http://127.0.0.1:8080")
client.login()

client.v3_fs_delete_file(
    name="disk",
    path="example.txt"
)
```

{% endtab %}

{% tab title="GoClient" %}

```go
import (
    "github.com/datarhei/core-client-go/v16"
)

client, _ := coreclient.New(coreclient.Config{
    Address: "https://127.0.0.1:8080",
})

err := client.FilesystemDeleteFile("disk", "/example.txt")
```

{% endtab %}
{% endtabs %}

Description:

{% openapi src="<https://demo.datarhei.com/api/swagger/doc.json>" path="/api/v3/fs/disk/{path}" method="delete" %}
<https://demo.datarhei.com/api/swagger/doc.json>
{% endopenapi %}

## Configuration

{% content-ref url="../../configuration/storage/disk" %}
[disk](https://docs.datarhei.com/core/configuration/storage/disk)
{% endcontent-ref %}
