---
title: Exploring the Capacitor File Compressor API
description: "Practical guide to the Capacitor File Compressor API: compress images and files at native speed in Ionic and Capacitor apps."
date: 
  created: 2025-07-10
  updated: 2026-07-17
authors:
  - robingenz
categories:
  - Capacitor
  - Guides
  - SDKs
links:
  - Capacitor File Compressor: sdks/capacitor/file-compressor.md
faq: true
---

# Exploring the Capacitor File Compressor API

File compression is a critical feature for modern mobile applications, especially when dealing with image uploads, storage optimization, and bandwidth management. With the [Capacitor File Compressor plugin](../../sdks/capacitor/file-compressor.md) from Capawesome, developers can seamlessly integrate powerful image compression capabilities into their Ionic and Capacitor applications, reducing file sizes while maintaining acceptable quality levels across Android, iOS, and Web platforms through a unified API that simplifies the complexity of platform-specific compression implementations.

<!-- more -->

## Installation

To install the Capacitor File Compressor plugin, please refer to the [Installation](../../sdks/capacitor/file-compressor.md/#installation) section in the plugin documentation.

## Usage

Let's explore the key features of the Capacitor File Compressor API and how to implement them effectively in your Ionic applications.

### Compressing Images

The primary functionality of the plugin is provided through the [`compressImage(...)`](../../sdks/capacitor/file-compressor.md#compressimage) method, which handles image compression with customizable quality settings:

```ts
import { FileCompressor } from '@capawesome-team/capacitor-file-compressor';

const compressImage = async (imagePath: string) => {
  const { path } = await FileCompressor.compressImage({
    mimeType: 'image/jpeg',
    path: imagePath,
    quality: 0.7,
  });
  return path;
};
```

The `compressImage(...)` method accepts several configuration options to control the compression process, including:

- `mimeType`: The output format (image/jpeg, image/png, or image/webp)
- `path`: The file path of the image to compress
- `quality`: Compression quality from 0.0 (maximum compression) to 1.0 (best quality)

For more aggressive compression, you can lower the quality value:

```ts
const compressImageHeavily = async (imagePath: string) => {
  const { path } = await FileCompressor.compressImage({
    mimeType: 'image/jpeg',
    path: imagePath,
    quality: 0.3, // Higher compression, lower quality
  });
  
  return path;
};
```

You can also specify different output formats based on your needs. For example, converting PNG images to JPEG for better compression:

```ts
const convertAndCompress = async (pngPath: string) => {
  const { path } = await FileCompressor.compressImage({
    mimeType: 'image/jpeg', // Convert PNG to JPEG
    path: pngPath,
    quality: 0.8,
  });
  
  return path;
};
```

You can also resize images while compressing them by specifying the desired height and/or width:

```ts
const compressAndResizeImage = async (imagePath: string, inputFormat: string) => {
  const { path } = await FileCompressor.compressImage({
    height: 800, // Resize height to 800 pixels
    mimeType: 'image/jpeg',
    path: imagePath,
    quality: 0.7,
    width: 600, // Resize width to 600 pixels
  });
  return path;
};
```

## Best Practices

When implementing image compression with the Capacitor File Compressor API, consider these best practices:

1. **Choose appropriate quality levels**: Balance file size reduction with visual quality by testing different quality values for your specific use case. Generally, values between 0.6 and 0.8 provide good compression while maintaining acceptable quality for most applications.

2. **Handle compression errors gracefully**: Implement comprehensive error handling to manage scenarios where compression fails, such as unsupported file formats or corrupted images. Always provide fallback options or user feedback when compression cannot be completed.

3. **Consider format conversion strategically**: Convert PNG images to JPEG format when transparency is not required, as JPEG typically provides better compression ratios. However, preserve PNG format when working with images that require transparency or when dealing with graphics with sharp edges and solid colors.

## FAQ

### Can I output a compressed image as PNG?

No — PNG is only supported as an input format, not as an output `mimeType`. On Android and web, you can compress to `image/jpeg` or `image/webp`; on iOS, only `image/jpeg` is supported as output. If you feed the plugin a PNG and set `mimeType: 'image/jpeg'`, it converts it to JPEG in the process — there's no way to get a compressed PNG back out.

### Does WebP output work the same on iOS as on Android?

No. WebP output is supported on Android and web, but iOS only supports `image/jpeg` as an output format. If your app needs consistent WebP output across all three platforms, iOS is the platform that won't support it — plan for a JPEG fallback there.

### What's the actual default quality if I don't set one?

`0.6`, on a `0.0` (maximum compression, lowest quality) to `1.0` (least compression, best quality) scale. If your app doesn't explicitly set `quality`, it isn't running uncompressed — it's already applying this default level.

### Does specifying `width` and `height` preserve the image's aspect ratio?

The plugin resizes to whatever width and height values you pass — it doesn't independently calculate and lock an aspect ratio for you. If you want to preserve the original proportions, you need to calculate the target `width`/`height` pair yourself based on the source image's dimensions before passing them in.

### Can I compress a `Blob` directly, or do I always need a file path?

It depends on the platform. On web, you pass a `blob`; on Android and iOS, you pass a `path` to the file instead. The two options aren't interchangeable across platforms — code that branches on `Capacitor.getPlatform()` to supply the right one is the typical pattern for a cross-platform implementation.

## Conclusion

The Capacitor File Compressor Plugin from Capawesome provides an efficient solution for integrating image compression into Ionic applications. By offering a unified API across multiple platforms, it enables developers to optimize file sizes and improve application performance without the complexity of platform-specific compression implementations.

To stay updated with the latest updates, features, and news about the Capawesome, Capacitor, and Ionic ecosystem, subscribe to the [Capawesome newsletter](/newsletter/){:target="_blank"} and follow us on [X (formerly Twitter)](https://x.com/capawesomeio){:target="_blank"}.

If you have any questions or need assistance with the Capacitor File Compressor Plugin, feel free to reach out to the Capawesome team. We're here to help you implement efficient image compression in your Ionic applications.
