# Preview File

Get a link that opens a file in the CloudFiles previewer, to show it in your own app or portal without downloading it.

> Kind: REST endpoint · Updated: Dec 3, 2026 · POST /v1/files/:fileId/preview

Returns a link that opens a file in the CloudFiles previewer. Open it in a new tab, or set it as the src of an iframe in your app.

The link works for 15 minutes if it is not opened. Once open, the preview stays active while it is on screen, for up to 8 hours. Anyone with the link can view the file until then, so create a new link each time a user opens a file and do not share it further.

### Path parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| fileId | string | required | The file's id, as Get File and the folder listings return it. |

### Query parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| library | string | optional | One of sharepoint, msteams, google, onedrive, box, dropbox, cloudfiles, s3, azure, hubspot, azurefiles, sftp |
| driveId | string | optional | Drive Id. Required when library is sharepoint or msteams. |

### Header parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| Authorization | string | required | Bearer API_Key. See Authentication. |
| Content-Type | string | optional | application/json, when you send a body. |

### Body parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| permissions | array of strings | optional | What the viewer can do, from the values below. Left out, the preview shows the file name and no buttons. |

## Permissions

| Value | What it turns on |
|---|---|
| show_header | The bar above the file with its name and buttons. Without it no buttons show, whatever else you grant. |
| download | The Download button. |
| print | The Print button. |
| open_in | The Open in menu, for example to open the file in SharePoint or in a desktop app. |
| edit | Lets the viewer annotate a PDF and save it as a new version of the same file, saved as the user the API key belongs to. |

Any other value is refused with 400. An empty list turns everything off.

## Example request

**cURL**
```bash
curl --request POST 'https://api.cloudfiles.io/v1/files/{fileId}/preview?library=sharepoint&driveId={driveId}' \
  --header 'Authorization: Bearer API_Key' \
  --header 'Content-Type: application/json' \
  --data '{
    "permissions": ["show_header", "download", "print"]
  }'
```

**JavaScript**
```js
const response = await fetch(
  "https://api.cloudfiles.io/v1/files/{fileId}/preview?library=sharepoint&driveId={driveId}",
  {
    method: "POST",
    headers: {
      Authorization: "Bearer API_Key",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ permissions: ["show_header", "download", "print"] }),
  }
);
const { url, expiresAt } = await response.json();
console.log(url, expiresAt);
```

**Ruby**
```ruby
require "uri"
require "json"
require "net/http"

url = URI("https://api.cloudfiles.io/v1/files/{fileId}/preview?library=sharepoint&driveId={driveId}")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer API_Key"
request["Content-Type"] = "application/json"
request.body = JSON.dump({ permissions: ["show_header", "download", "print"] })

response = https.request(request)
puts JSON.parse(response.read_body)["url"]
```

**Python**
```py
import requests

response = requests.post(
    "https://api.cloudfiles.io/v1/files/{fileId}/preview",
    params={"library": "sharepoint", "driveId": "{driveId}"},
    headers={"Authorization": "Bearer API_Key"},
    json={"permissions": ["show_header", "download", "print"]},
)
print(response.json()["url"])
```

## Response body

201 Created. Send the user to url or load it in an iframe. expiresAt is when the link stops working if it has not been opened.

```json
{
  "url": "https://salesforce.cloudfiles.io/preview/files?code=3f9c2a7d4e1b8c6a0d5f2e9b7a1c4d8e",
  "expiresAt": "2026-12-07T10:15:00.000Z"
}
```

## Errors

| Status | What it means |
|---|---|
| 400 | permissions is not a list or has a value not in the table above, or fileId is a folder. |
| 403 | The API key is missing or unknown. |
| 404 | The file does not exist in that library or drive. |
