> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squarecloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Go SDK: app file manager

> List, read, write, move and delete the files of an application with c.Apps.Files. Content travels as base64, so text and binary files round-trip byte for byte.

The file manager lives on `c.Apps.Files`. Every method takes `ctx` and the app id first, then a path inside the app. Paths are at most **256 characters**.

Each snippet below runs on its own inside this program: paste one at a time into `main` and run `goimports` (see [Running the examples](/en/sdks/go/client#running-the-examples)).

```go theme={"system"}
package main

import (
	"context"
	"os"

	"github.com/squarecloudofc/sdk-api-go/v3"
)

var (
	ctx   = context.Background()
	c     = squarecloud.New(os.Getenv("SQUARECLOUD_API_KEY"))
	appID = "abc123def456abc123def456"
)

func main() {
	// Paste one snippet here, then run goimports.
}
```

## Listing a directory

`Files.List(ctx, appID, path)` lists a directory (`""` for the app root).

```go theme={"system"}
entries, err := c.Apps.Files.List(ctx, appID, "/src")
if err != nil {
	log.Fatal(err)
}
for _, entry := range entries {
	fmt.Println(entry.Type, entry.Name, entry.Size)
	if entry.LastModified != nil {
		fmt.Println(time.UnixMilli(int64(*entry.LastModified)))
	}
}
```

| Field | Type | Description |
| - | - | - |
| `Name` (`name`) | `string` | Entry name |
| `Type` (`type`) | `string` | `"file"` or `"directory"` |
| `Size` (`size`) | `int64` | Size in bytes. `0` on directory entries the API sends without it |
| `LastModified` (`lastModified`) | `*float64` | Unix ms (may carry a fraction); `nil` when unreadable |

A directory that does not exist is 404 `FILE_NOT_FOUND`. A path the file manager does not expose is 403 `BLOCKED_PATH`.

## Reading a file

`Files.Read(ctx, appID, path)` returns the file's bytes as a `[]byte`. Files are limited to **10 MB**: a larger one is 413 `FILE_TOO_LARGE`.

```go theme={"system"}
data, err := c.Apps.Files.Read(ctx, appID, "/config.json")
if err != nil {
	log.Fatal(err)
}

var config map[string]any
if err := json.Unmarshal(data, &config); err != nil {
	log.Fatal(err)
}
fmt.Println(config)
```

## Writing a file

`Files.Write(ctx, appID, path, content)` creates or overwrites a file. `content` is a `[]byte`:

* It is **always sent as base64**, so text and binary content round-trip byte for byte. To write a string, pass `[]byte(s)`.
* Empty content (`nil` or an empty slice) creates an empty file.

```go theme={"system"}
// Text
config, err := json.Marshal(map[string]bool{"debug": false})
if err != nil {
	log.Fatal(err)
}
if err := c.Apps.Files.Write(ctx, appID, "/config.json", config); err != nil {
	log.Fatal(err)
}

// Binary
res, err := http.Get("https://example.com/logo.png")
if err != nil {
	log.Fatal(err)
}
defer res.Body.Close()
image, err := io.ReadAll(res.Body)
if err != nil {
	log.Fatal(err)
}
if err := c.Apps.Files.Write(ctx, appID, "/assets/logo.png", image); err != nil {
	log.Fatal(err)
}
```

Content over **10 MB** fails locally with `FILE_TOO_LARGE` (status `0`) before anything is sent. Content over **1 MiB** gets no default deadline, like an upload: bound or cancel it with `ctx`. For larger files, use [`Apps.Commit`](/en/sdks/go/commit_and_upload).

<Note>
  Writing does not restart the app. Call [`Apps.Restart`](/en/sdks/go/managing_application#start-stop-and-restart) to apply the change.
</Note>

## Moving or renaming a file

```go theme={"system"}
if err := c.Apps.Files.Move(ctx, appID, "/config.json", "/config.old.json"); err != nil {
	log.Fatal(err)
}
```

## Deleting a file

```go theme={"system"}
if err := c.Apps.Files.Delete(ctx, appID, "/config.old.json"); err != nil {
	log.Fatal(err)
}
```

## Errors

| Status | Code | When |
| - | - | - |
| 0 | `FILE_TOO_LARGE` | `Write` content over 10 MB (checked locally) |
| 400 | `INVALID_PATH` | The path fails validation (traversal, invalid characters, too long), or `Move` to the same path |
| 400 | `DELETE_FAILED`, `RENAME_FAILED` | The cluster could not delete or rename the file |
| 403 | `BLOCKED_PATH` | The path is not exposed by the file manager |
| 403 | `PERMISSION_DENIED` | Your workspace role cannot touch a restricted file (such as `.env`) |
| 404 | `FILE_NOT_FOUND` | The file or directory does not exist |
| 413 | `FILE_TOO_LARGE` | `Read` of a file over 10 MB |
| 429 | `KEEP_CALM` | More than 10 writes in 5 seconds |

See [Errors](/en/sdks/go/errors) for the codes every call can return.

## Next steps

<CardGroup cols={3}>
  <Card title="Environment variables" icon="key" href="/en/sdks/go/environment_variables">
    Read and change the variables of an app.
  </Card>

  <Card title="File manager API reference" icon="code" href="/en/api-reference/endpoint/apps/filemanager/list">
    The REST endpoints behind these methods.
  </Card>

  <Card title="Manage files from the CLI" icon="terminal" href="/en/cli-reference/files">
    The same actions from the terminal.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.