# Serve files to web browsers

🤖/file/serve serves files to web browsers.

![/file/serve Robot](/assets/images/robots/240x240/file-serve.png)

When you want Transloadit to tranform files on the fly, you can use this Robot to determine which Step of a Template should be served to the end-user (via a CDN), as well as set extra information on the served files, such as headers. This way you can for instance suggest the CDN for how long to keep cached copies of the result around. By default, we instruct browsers to cache the result for 72h (`259200` seconds) and CDNs to cache the content for 24h (`86400` seconds). Use the `cache_duration` parameter to customize both values at once.

🤖/file/serve merely acts as the glue layer between our Assembly engine and serving files over HTTP. It let's you pick the proper result of a series of Steps via the `use` parameter and configure headers on the original content. That is where its responsibilies end, and 🤖/tlcdn/deliver, then takes over to globally distribute this original content across the globe, and make sure that is cached close to your end-users, when they make requests such as [https://my-app.tlcdn.com/resize-img/canoe.jpg?w=500⁠](https://my-app.tlcdn.com/resize-img/canoe.jpg?w=500), another. 🤖/tlcdn/deliver is not a part of your Assembly Instructions, but it may appear on your invoices as bandwidth charges incur when distributing the cached copies. 🤖/file/serve only charges when the CDN does not have a cached copy and requests to regenerate the original content, which depending on your caching settings could be just once a month, or year, per file/transformation.

While theoretically possible, you could use [🤖/file/serve](/docs/robots/file-serve.md) directly in HTML files, but we strongly recommend against this, because if your site gets popular and the media URL that /file/serve is handling gets hit one million times, that is one million new image resizes. Wrapping it with a CDN (and thanks to the caching that comes with it) makes sure encoding charges stay low, as well as latencies.

Also consider configuring caching headers and cache-control directives to control how content is cached and invalidated on the CDN edge servers, balancing between freshness and efficiency.

## Smart CDN security with signed URLs

You can leverage [signed Smart CDN URLs](/docs/api/authentication.md#smart-cdn) to avoid abuse of our encoding platform. Below is a quick Node.js example using our Node SDK, but there are [examples for other languages and SDKs](/docs/api/authentication.md#example-code) as well.

```javascript
// yarn add transloadit
// or
// npm install --save transloadit

import { Transloadit } from 'transloadit'

const transloadit = new Transloadit({
  authKey: 'YOUR_TRANSLOADIT_KEY',
  authSecret: 'YOUR_TRANSLOADIT_SECRET',
})

const url = transloadit.getSignedSmartCDNUrl({
  workspace: 'YOUR_WORKSPACE',
  template: 'YOUR_TEMPLATE',
  input: 'image.png',
  urlParams: { height: 100, width: 100 },
})

console.log(url)

```

This will generate a signed Smart CDN URL that includes authentication parameters, preventing unauthorized access to your transformation endpoints.

For new integrations, use the modern `sig` + `exp` format. Legacy `s` signatures are deprecated. Also note that the expiration window is the practical cache window for signed results: shorter expirations tighten access control, while longer expirations improve cache reuse and lower encoding volume.

## More information

* [Content Delivery](/services/content-delivery.md)
* [🤖/file/serve](/docs/robots/file-serve.md) pricing
* [🤖/tlcdn/deliver](/docs/robots/tlcdn-deliver.md) pricing
* [File Preview Feature](/blog/2024/06/file-preview-with-smart-cdn.md) blog post

<span aria-hidden="true" id="usage-example"></span>

## Usage example

Serve transformed files with explicit browser and CDN cache duration:

```
{
  "steps": {
    "resized": {
      "robot": "/image/resize",
      "use": ":original",
      "width": 800,
      "height": 450,
      "resize_strategy": "fit"
    },
    "served": {
      "robot": "/file/serve",
      "use": "resized",
      "cache_duration": 86400
    }
  }
}
```

<span aria-hidden="true" id="parameters"></span>

## Parameters

* <span aria-hidden="true" id="interpolate"></span>

### `interpolate`

`boolean | Record<string, boolean>`\
Controls whether Assembly Variables are interpolated for individual instruction fields.\
By default, most Robot instruction fields interpolate Assembly Variables. Set this to `false` to treat every instruction field as literal text, or set an individual field path to `false` to treat only that field as literal text. For Robot-specific fields that are literal by default, set this to `true` or set that field path to `true` to opt back into interpolation.\
Use field names such as `path`, or dotted paths such as `ffmpeg.vf` for nested objects.

* <span aria-hidden="true" id="output_meta"></span>

### `output_meta`

`Record<string, boolean> | boolean | Array<string>`\
Allows you to specify a set of metadata that is more expensive on CPU power to calculate, and thus is disabled by default to keep your Assemblies processing fast.\
For images, you can add `"has_transparency": true` in this object to extract if the image contains transparent parts and `"dominant_colors": true` to extract an array of hexadecimal color codes from the image.\
For images, you can also add `"blurhash": true` to extract a [BlurHash⁠](https://blurha.sh) string — a compact representation of a placeholder for the image, useful for showing a blurred preview while the full image loads.\
For videos, you can add the `"colorspace": true` parameter to extract the colorspace of the output video.\
For videos, you can also add `"interlaced": true` to detect whether the video is interlaced. This combines the cheap ffprobe `field_order` flag with a bounded `idet` sampling pass over the first frames of the source, exposing `interlaced`, `field_order`, and a diagnostic `interlace_detection` object under `file.meta`. This is computationally expensive and billed accordingly.\
For audio, you can add `"mean_volume": true` to get a single value representing the mean average volume of the audio file.\
You can also set this to `false` to skip metadata extraction and speed up transcoding.

* <span aria-hidden="true" id="user_meta"></span>

### `user_meta`

`Record<string, any>`(default: `{}`)\
Adds custom metadata to each file emitted by this Robot without modifying the file’s contents.\
The values are merged with any existing `user_meta` carried by the input file. If both objects contain the same key, this Robot’s value takes precedence. Assembly Variables are supported, for example `{ "internal_file_id": "${file.id}" }`.

* <span aria-hidden="true" id="result"></span>

### `result`

`boolean`(default: `false`)\
Whether the results of this Step should be present in the Assembly Status JSON

* <span aria-hidden="true" id="queue"></span>

### `queue`

`batch`\
Setting the queue to 'batch', manually downgrades the priority of jobs for this step to avoid consuming Priority job slots for jobs that don't need zero queue waiting times

* <span aria-hidden="true" id="force_accept"></span>

### `force_accept`

`boolean`(default: `false`)\
Force a Robot to accept a file type it would have ignored.\
By default, Robots ignore files they are not familiar with.[🤖/video/encode](/docs/robots/video-encode.md), for example, will happily ignore input images.\
With the `force_accept` parameter set to `true`, you can force Robots to accept all files thrown at them. This will typically lead to errors and should only be used for debugging or combatting edge cases.

* <span aria-hidden="true" id="ignore_errors"></span>

### `ignore_errors`

`boolean | Array<meta | execute>`(default: `[]`)\
Ignore errors during specific phases of processing.\
Setting this to `["meta"]` will cause the Robot to ignore errors during metadata extraction.\
Setting this to `["execute"]` will cause the Robot to ignore errors during the main execution phase.\
Setting this to `true` is equivalent to `["meta", "execute"]` and will ignore errors in both phases.

* <span aria-hidden="true" id="use"></span>

### `use`

`string | Array<string> | Array<object> | object`\
Specifies which Step(s) to use as input.

* You can pick any names for Steps except `":original"` (reserved for user uploads handled by Transloadit)
* You can provide several Steps as input with arrays:

```json
{  
  "use": [  
    ":original",  
    "encoded",  
    "resized"  
  ]  
}  
```

* You can also tag input Steps with `as` to pass semantic intent to robots:

```json
{  
  "use": [  
    {  
      "name": ":original",  
      "as": "image"  
    },  
    {  
      "name": ":original",  
      "as": "mask"  
    }  
  ]  
}  
```

**Tip**\
That's likely all you need to know about `use`, but you can view [Advanced use cases](/docs/topics/use-parameter.md).

* <span aria-hidden="true" id="cache_duration"></span>

### `cache_duration`

`string | number`\
An optional duration in seconds that the served file should be cached. When set, this value is used for both the `max-age` (browser cache) and `s-maxage` (shared/CDN cache) directives in the `Cache-Control` header, overriding the defaults. For example, setting `cache_duration` to `43200` would cache the file for 12 hours.\
This is useful for controlling data retention in CDNs. For instance, if your temporary files are deleted after 24 hours, you can set `cache_duration` to `86400` to ensure cached copies also expire within that window.

* <span aria-hidden="true" id="headers"></span>

### `headers`

`Record<string, string>`(default: `{"Access-Control-Allow-Headers":"X-Requested-With, Content-Type, Cache-Control, Accept, Content-Length, Transloadit-Client, Authorization, Range, If-Range","Access-Control-Allow-Methods":"POST, GET, PUT, DELETE, OPTIONS","Access-Control-Allow-Origin":"*","Access-Control-Expose-Headers":"Transloadit-Assembly-URL, Content-Range, Content-Length, Accept-Ranges","Cache-Control":"public, max-age=259200, s-maxage=86400","Content-Type":"${file.mime}; charset=utf-8","Transloadit-Assembly":"…","Transloadit-RequestID":"…","Accept-Ranges":"bytes"}`)\
An object containing a list of headers to be set for a file as we serve it to a CDN/web browser, such as `{ FileURL: "${file.url_name}" }` which will be merged over the defaults, and can include any available [Assembly Variable](/docs/topics/assembly-instructions.md#assembly-variables).\
The `Accept-Ranges: bytes` header advertises that HTTP range requests are supported for seekable media playback. This relies on Transloadit's storage backends (S3, GCS, etc.) all honoring Range request headers. The CORS headers include `Range` and `If-Range` in `Access-Control-Allow-Headers` to permit cross-origin range requests, and expose `Content-Range`, `Content-Length`, and `Accept-Ranges` via `Access-Control-Expose-Headers` so browser JavaScript can read these values.

<span aria-hidden="true" id="related-blog-posts"></span>

## Related blog posts

* [Building an alt-text to speech generator with Transloadit](/blog/2022/05/image-tts.md) May 9, 2022
* [Easy instant website screenshots via Transloadit CDN](/blog/2022/05/website-preview.md) May 11, 2022
* [Smart CDN enhanced with AI-powered face detection](/blog/2022/06/image-facedetect-cdn-support.md) June 21, 2022
* [How to get started with the Transloadit Smart CDN](/blog/2024/02/getting-started-with-tlcdn.md) February 16, 2024
* [Save costs with on-demand video encoding](/blog/2025/05/on-demand-video-encoding.md) May 5, 2025
