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

# Ruby

> Upload files, manage folders, and call the full Autorender API from your Ruby server.

The `autorender` gem is the official server-side client for Ruby. Use it to upload files, list and manage files and folders, run multipart uploads, and call the Autorender API from your backend.

## Prerequisites

* An Autorender account with an API key — [create one in the dashboard](https://app.autorender.io)
* Ruby **3.0** or later

## Guide

<Steps>
  <Step title="Install the gem.">
    <CodeGroup>
      ```ruby Gemfile theme={null}
      gem "autorender", "~> 0.2.1"
      ```

      ```bash gem install theme={null}
      gem install autorender
      ```
    </CodeGroup>

    If you added it to your `Gemfile`, install with Bundler:

    ```bash theme={null}
    bundle install
    ```
  </Step>

  <Step title="Set your API key.">
    Create an API key in the dashboard and set it as an environment variable:

    ```bash theme={null}
    export AUTORENDER_API_KEY=your-api-key
    ```
  </Step>

  <Step title="Upload a file.">
    Create a client and upload your first file. Read `AUTORENDER_API_KEY` from the environment — never hardcode the key.

    ```ruby {3} theme={null}
    require "autorender"

    client = Autorender::Client.new(api_key: ENV["AUTORENDER_API_KEY"])

    upload = client.uploads.create(
      file: File.open("products/chair.jpg"),
      file_name: "chair.jpg"
    )

    puts upload.file_no  # e.g. "fi_abc123"
    puts upload.url      # CDN URL
    ```
  </Step>
</Steps>

## Examples

### Upload from URL

```ruby theme={null}
upload = client.uploads.create_from_url(
  remote_url: "https://acme-assets.s3.amazonaws.com/products/chair.jpg"
)
```

### List files

```ruby theme={null}
result = client.files.list(limit: 10)

result.files.each do |file|
  puts "#{file.file_no} #{file.name} #{file.url}"
end
```

### Get file details

```ruby theme={null}
file = client.files.retrieve("fi_abc123")
puts file.data.url
```

### Rename a file

```ruby theme={null}
client.files.rename("fi_abc123", name: "new-name")
```

### Delete a file

```ruby theme={null}
client.files.delete("fi_abc123")
```

### Folders

```ruby theme={null}
# List folders
result = client.folders.list

# Create a folder
folder = client.folders.create(name: "products")

# Rename a folder
client.folders.rename(folder.data.folder_no, name: "product-images")

# Delete a folder
client.folders.delete(folder.data.folder_no)
```

### Multipart upload

For files larger than **100 MB**, use a multipart upload to split the file into parts:

```ruby theme={null}
require "net/http"
require "uri"

file_data = File.binread("large-video.mp4")

# Start session
session = client.multipart_uploads.start(
  file_name: "large-video.mp4",
  file_size: file_data.bytesize
)

# Upload parts
uri = URI(session.parts[0].url)
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
  http.send_request("PUT", uri.request_uri, file_data)
end
etag = res["etag"]

# Complete
client.multipart_uploads.complete(
  upload_id: session.upload_id,
  parts: [{ part_number: 1, etag: etag }]
)
```

### Error handling

```ruby theme={null}
begin
  client.files.retrieve("fi_notexist")
rescue Autorender::Errors::NotFoundError => e
  puts e.status   # 404
  puts e.message
rescue Autorender::Errors::APIStatusError => e
  puts e.status
  puts e.message
end
```

## Resources

* [RubyGems](https://rubygems.org/gems/autorender)
* [GitHub](https://github.com/autorender/autorender-ruby)

## Next steps

<CardGroup cols={2}>
  <Card title="Direct upload API" icon="cloud-arrow-up" iconType="solid" href="/docs/api-reference/direct-upload">
    The upload endpoint this SDK calls.
  </Card>

  <Card title="Create an API key" icon="key" iconType="solid" href="/docs/create-an-api-key">
    Generate the key the client reads from the environment.
  </Card>

  <Card title="Image transformations" icon="wand-magic-sparkles" iconType="solid" href="/docs/transformations/introduction">
    Build delivery URLs from your uploaded files.
  </Card>

  <Card title="All SDKs" icon="cubes" iconType="solid" href="/docs/resources/sdks">
    Server-side clients for every language.
  </Card>
</CardGroup>
