# PUT /files/{user}/content

First published 3 Oct 2026 (release 0.1.0) · Unchanged since publication

UrbeStack release 0.2.35 API operation in the files group.

Write the entire contents of a file

- Who may call it: administrator, reseller, customer
- Token scope, any of: files, all
- Answers: 200 OK

For a raw upload, use Content-Type application/octet-stream, supply path in the query, and set Content-Length to the exact byte count. Use 0 for an empty file. The API returns 411 if Content-Length is missing. It checks the declared length against files.upload_limit_mb before reading the body and returns 413 with a message directing you to SFTP if the length exceeds the limit. The API streams the upload and puts it in place only after receiving all declared bytes. If the upload ends early, the API returns 400 and any existing file stays in place. The API returns 507 if there is insufficient disk space or the upload exceeds the disk quota.

For an editor save or other small write, use Content-Type application/json and supply path and base64-encoded content in the body. The API returns 400 if content contains characters outside the standard base64 alphabet, padding, and line breaks. The same files.upload_limit_mb ceiling applies to the decoded file size. The API returns 403 if it cannot open the file for writing and 500 if writing or closing the file fails.

Set create_only in the query for a raw upload or in the body for JSON. When true, the API returns 201 for a new file or 409 if the destination exists. When false or omitted, the API returns 200 on success. The write uses the customer's permissions and refuses to follow symbolic links. New files get mode 0644, and replacements retain the existing mode.

## As a command

- [urbestack-file-write](https://urbestack.com/docs/commands/urbestack-file-write.md): Writes the entire contents of a file in the customer's home directory from standard input, up to the size set by files.upload_limit_mb.

## Parameters

- `user` (path, Username, required): Username of the customer who owns the home directory. Administrators can specify any customer, and customers can specify only themselves.
- `path` (query, HomePath): File path starting with /, required in the query for application/octet-stream. For application/json, supply path in the body.
- `create_only` (query, boolean): Whether to create a new file only when sending application/octet-stream. Defaults to false and returns 409 if true and the destination already exists.

## Request body

JSON, the type [FileWrite](https://urbestack.com/docs/api/types/FileWrite.md).

- `content` (string, required): File bytes encoded in base64, with the decoded size limited by files.upload_limit_mb.
- `path` (HomePath, required): A path within the customer's home directory, with / representing the home directory itself. The path cannot contain .. components or control characters.
- `create_only` (boolean): Whether to create a new file only. When true, an existing file at path results in 409.

## Example

Set $API to the base URL and $TOKEN to the token, as the [API overview](https://urbestack.com/docs/api.md) shows.

```
curl -sS -X PUT "$API/files/alice/content?path=public_html/index.php&create_only=1" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/octet-stream" \
  --data-binary @file

curl -sS -X PUT "$API/files/alice/content" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "text",
    "create_only": true,
    "path": "public_html/index.php"
  }'
```

Response, 200 OK:

```
{
  "file": {
    "inside": true,
    "mode": "text",
    "modified": "text",
    "name": "alice",
    "owner": "text",
    "path": "public_html/index.php",
    "size": 1,
    "target": "https://example.com/new",
    "target_type": "dir",
    "text": true,
    "type": "dir"
  }
}
```

## Errors

- 400: --content-stdin is required: the content, base64, comes on standard input
- 400: --length is required with --bytes-stdin: how many bytes come
- 400: --path is required
- 400: --user is required
- 400: <name> is an administrator: administrators have no home
- 400: <what> climbs out of the home with ..
- 400: <what> has a name over 255 characters
- 400: <what> holds a control character
- 400: <what> is required
- 400: <what> is too long
- 400: <what> must start with /, which is the home
- 400: Invalid boolean
- 400: Invalid username: 2 to 32 lowercase letters, digits or underscores, starting with a letter
- 400: Username '<value>' is reserved
- 400: content must be base64
- 400: path is required: the file goes up with its path in the query
- 401: Authentication required
