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

# File Storage

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Create Image Metadata

```xs theme={null}
storage.create_image {
  access = "public"
  value = $input.file
  filename = ""
} as image_metadata
```

| Parameter | Purpose                               | Example                            |
| --------- | ------------------------------------- | ---------------------------------- |
| access    | Access level for the stored image     | `public`, `private`                |
| value     | Source file to create image from      | `$input.file`, `$file.data`        |
| filename  | Name for the stored image file        | `"profile.jpg"`, `"avatar.png"`    |
| as        | Alias to reference the image metadata | `image_metadata`, `uploaded_image` |

<Accordion title="Example">
  ```xs theme={null}
  storage.create_image {
    access = "public"
    value = $input.profile_photo
    filename = "user_"|add:$user.id|add:"_profile.jpg"
  } as profile_image
  ```

  * Creates metadata about the stored image
</Accordion>

<Accordion title="Private Access Example">
  ```xs theme={null}
  storage.create_image {
    access = "private"
    value = $input.profile_photo
    filename = "user_"|add:$user.id|add:"_private.jpg"
  } as private_profile_image
  ```

  * Stores the image as private (requires signed URL to access)
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Create Video Metadata

```xs theme={null}
storage.create_video {
  access = "public"
  value = $image_metadata
  filename = ""
} as x1
```

| Parameter | Purpose                               | Example                          |
| --------- | ------------------------------------- | -------------------------------- |
| access    | Access level for the stored video     | `public`, `private`              |
| value     | Source file to create video from      | `$input.video`, `$file.data`     |
| filename  | Name for the stored video file        | `"video.mp4"`, `"recording.mov"` |
| as        | Alias to reference the video metadata | `x1`, `video_data`               |

<Accordion title="Example">
  ```xs theme={null}
  storage.create_video {
    access = "public"
    value = $input.video_upload
    filename = "video_"|add:$timestamp|add:".mp4"
  } as uploaded_video
  ```

  * Creates metadata for a video file
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Create Audio Metadata

```xs theme={null}
storage.create_audio {
  access = "public"
  value = $input.file
  filename = ""
} as x2
```

| Parameter | Purpose                               | Example                          |
| --------- | ------------------------------------- | -------------------------------- |
| access    | Access level for the stored audio     | `public`, `private`              |
| value     | Source file to create audio from      | `$input.file`, `$audio.data`     |
| filename  | Name for the stored audio file        | `"recording.mp3"`, `"audio.wav"` |
| as        | Alias to reference the audio metadata | `x2`, `audio_data`               |

<Accordion title="Example">
  ```xs theme={null}
  storage.create_audio {
    access = "public"
    value = $input.audio_upload
    filename = "audio_"|add:$timestamp|add:".mp3"
  } as uploaded_audio
  ```

  * Creates metadata for audio file
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Create Attachment Metadata

```xs theme={null}
storage.create_attachment {
  access = "public"
  value = $input.file
  filename = ""
} as x3
```

| Parameter | Purpose                                    | Example                                |
| --------- | ------------------------------------------ | -------------------------------------- |
| access    | Access level for the stored attachment     | `public`, `private`                    |
| value     | Source file to create attachment from      | `$input.file`, `$document.data`        |
| filename  | Name for the stored attachment             | `"document.pdf"`, `"spreadsheet.xlsx"` |
| as        | Alias to reference the attachment metadata | `x3`, `file_data`                      |

<Accordion title="Example">
  ```xs theme={null}
  storage.create_attachment {
    access = "public"
    value = $input.document
    filename = "file_"|add:$user.id|add:"_"|add:$original_filename
  } as uploaded_file
  ```

  * Creates metadata for the attachment
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Create File Resource

```xs theme={null}
storage.create_file_resource {
  filename = "filename.ext"
  filedata = "filedata"
}
```

| Parameter | Purpose                    | Example                          |
| --------- | -------------------------- | -------------------------------- |
| filename  | Name of the file to create | `"document.txt"`, `"data.json"`  |
| filedata  | Content of the file        | `"Hello World"`, `$encoded_data` |

<Accordion title="Example">
  ```xs theme={null}
  storage.create_file_resource {
    filename = "export_"|add:$timestamp|add:".csv"
    filedata = $processed_data|to_csv
  }
  ```

  * Creates a file resource from provided data
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Get File Resource Data

```xs theme={null}
storage.read_file_resource {
  value = $input.file
} as file2
```

| Parameter | Purpose                              | Example                          |
| --------- | ------------------------------------ | -------------------------------- |
| value     | File resource to read                | `$input.file`, `$stored_file.id` |
| as        | Alias to reference the file contents | `file2`, `file_contents`         |

<Accordion title="Example">
  ```xs theme={null}
  storage.read_file_resource {
    value = $stored_document.id
  } as document_contents
  ```

  * Reads contents of a stored file resource
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Delete File

```xs theme={null}
storage.delete_file {
  pathname = "/path/to/file.ext"
}
```

| Parameter | Purpose                    | Example                             |
| --------- | -------------------------- | ----------------------------------- |
| pathname  | Path to the file to delete | `"/path/to/file.ext"`, `$file.path` |

<Accordion title="Example">
  ```xs theme={null}
  storage.delete_file {
    pathname = "/uploads/"|add:$file.name
  }
  ```

  * Deletes a file from the specified path
  * Requires full path to the file
  * Permanently removes the file
  * Use with caution as deletion cannot be undone
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Sign Private File URL

```xs theme={null}
storage.sign_private_url {
  pathname = "/path/to/privatefile.ext"
  ttl = 30
} as x4
```

| Parameter | Purpose                                    | Example                                    |
| --------- | ------------------------------------------ | ------------------------------------------ |
| pathname  | Path to the private file                   | `"/path/to/privatefile.ext"`, `$file.path` |
| ttl       | Time-to-live in seconds for the signed URL | `30`, `3600`, `86400`                      |
| as        | Alias to reference the signed URL          | `x4`, `signed_url`                         |

<Accordion title="Example">
  ```xs theme={null}
  storage.sign_private_url {
    pathname = $private_file.path
    ttl = 3600
  } as temporary_url
  ```

  * Generates a temporary signed URL for accessing private files
</Accordion>

***

## Notes on Returned Metadata

All `storage.create_*` functions return a metadata object with fields such as:

* `id`: Unique identifier for the file resource
* `name`: File name
* `size`: File size in bytes
* `mime`: MIME type
* `path`: Storage path
* `url`: Public URL (if access is public)
* `created_at`: Timestamp

Refer to the XanoScript documentation for the full schema.

## Error Handling Example

If you attempt to read or delete a file that does not exist, Xano will throw an error. You can handle this with `try_catch`:

```xs theme={null}
try_catch {
  try {
    storage.read_file_resource {
      value = $input.file
    } as file_contents
  }
  catch {
    debug.log {
      value = "File not found or could not be read."
    }
  }
}
```
