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

# Download file

> Control file downloads and inline viewing with Content-Disposition headers, or download files and images with the JavaScript Bridge.

Your app can handle file downloads and inline viewing by following the header set by your server. This allows you to control whether files are displayed within the app's webview or downloaded to the user's device.

## Supported content-disposition headers

### `Content-Disposition: inline`

Files with this header will be displayed directly in the app's webview, similar to how HTML content is rendered.

* Ideal for PDFs and other media intended to be viewed in-app.
* You may need to use [Native Navigation](https://docs.median.co/docs/native-navigation-overview.md) to provide navigation options for users to return to other parts of your app.

### `Content-Disposition: attachment`

Files with this header will be automatically downloaded to the user's device:

* iOS: Triggers the native “Share” dialog, allowing the user to open the file in the Files app or compatible apps.
* Android: Prompts the user with an “Open with” dialog after download.

## Implementation guide

If you are not able to set the `Content-Disposition` header you may use the JavaScript Bridge `downloadFile` function to download (and open) a file on a user's device. If you choose to open the file, the user sees the native iOS or Android **Open with** dialog.

URLs need to be publicly available. Localhost URLs are **not supported**.

> [!TIP]
>
> **Developer Demo**
>
> You can see the PDF viewer in action on our demo page [https://median.dev/pdf-download](https://median.dev/pdf-download)

### Download file at specified URL

Use the following command to download a file via the Median JavaScript Bridge:

To download a file:

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.share.downloadFile({url: 'https://yoursite.com/file.pdf', open: true})
// 'open' is an Android-only parameter: true or false. See Android behavior below.
```

**iOS behavior**

* The file is downloaded and passed to the native “Open with” system dialog.

**Android behavior**

* Downloads Folder Enabled (Permissions tab): Downloads silently. If `open: true` is set, the "Open with" dialog is displayed.
* Private to App Enabled (Permissions tab): Always shows the "Open with" dialog after download.

Learn more about these permissions in [Downloads directory](https://docs.median.co/docs/downloads-directory.md).

### Save image to photos

To download and save an image to the user’s photo gallery (iOS Photos or Android Gallery), use:

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.share.downloadImage({url: 'https://yoursite.com/file.jpg'})
```

> [!TIP]
>
> **Test  with our demo page**
>
> We host a ready-made demo page at
>
> that calls the  features through the Median JavaScript Bridge.
> Load it inside your Median app during development, either by setting it
> as your app's website URL in App Studio or by navigating to it from your
> own site, and use it to confirm  works on a real device before
> you add it to your own pages.
>
> The demo page only works inside a Median app with  enabled.
> Opened in a regular mobile or desktop browser, the native features
> won't respond. Remember to switch your app back to your own URL before
> release.

### Viewing PDF files in the app

You can view PDF files directly within your app using one of the following methods:

**Option 1: Open via URL**

```javascript JavaScript theme={null}
// Navigate to the PDF file's URL
window.location.href = 'https://yoursite.com/file.pdf';
```

**Option 2: Use JavaScript Bridge**

Median JavaScript Bridge

```javascript JavaScript theme={null}
// Use the downloadFile function
median.share.downloadFile({url: 'https://yoursite.com/file.pdf', open: true})
```

On iOS, Median uses Apple's built-in PDFKit framework. On Android, Median uses the [Pdf-Viewer library](https://github.com/afreakyelf/Pdf-Viewer).

| iOS | Android |
| :-: | :-: |
| ![PDF viewer on iOS](https://mintcdn.com/median-co/yvThAkXSLqPa6nzP/images/docs/docs/pdf-viewer/pdf-viewer-ios.png?fit=max\&auto=format\&n=yvThAkXSLqPa6nzP\&q=85\&s=d6ff4e8bd77dc6a3df924680f17a7f89) | ![PDF viewer on Android](https://mintcdn.com/median-co/yvThAkXSLqPa6nzP/images/docs/docs/pdf-viewer/pdf-viewer-android.png?fit=max\&auto=format\&n=yvThAkXSLqPa6nzP\&q=85\&s=c0ff35e5a9668893ac4aa954adb8567b) |

### Printing PDF files

If the device supports printing services, users can print PDF files directly from the viewer:

* iOS: Tap the Print icon in the bottom-right corner of the PDF viewer.
* Android: Tap the Print icon in the top-right corner.


## Related topics

- [Offline download manager](https://docs.median.co/docs/offline-download-manager.md)
- [Salesforce LWC component deployment and reference](https://docs.median.co/docs/salesforce-lwc-components.md)
- [JavaScript Bridge overview](https://docs.median.co/docs/javascript-bridge.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.