@capacitor-firebase/storage

中文文档
8.6.0发布于 2026/10/31Apache-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 1.1万

Capacitor plugin for Firebase Cloud Storage on Android, iOS, and Web.

原始使用文档
文档目录39 节
  1. Use Cases
  2. Compatibility
  3. Guides
  4. Installation
  5. Android
  6. iOS
  7. Configuration
  8. Demo
  9. Starter templates
  10. Usage
  11. Upload a file
  12. Download a file
  13. Download a file with the Filesystem plugin
  14. Get a download URL
  15. List files in a directory
  16. Read and update file metadata
  17. Delete a file
  18. Use the Cloud Storage emulator
  19. API
  20. deleteFile(...)
  21. getDownloadUrl(...)
  22. getMetadata(...)
  23. listFiles(...)
  24. updateMetadata(...)
  25. downloadFile(...)
  26. uploadFile(...)
  27. useEmulator(...)
  28. Interfaces
  29. Type Aliases
  30. FAQ
  31. How do I track the progress of an upload or download?
  32. How does downloading a file differ between the platforms?
  33. How do I upload a file selected by the user?
  34. How can I store additional information about a file?
  35. Can I test against the Cloud Storage emulator?
  36. Related Plugins
  37. Newsletter
  38. Changelog
  39. License

Capacitor Firebase Cloud Storage Plugin

Unofficial Capacitor plugin for Firebase Cloud Storage.[^1]

Use Cases

The Firebase Cloud Storage plugin is typically used to store and serve user-generated content, for example:

  • User-generated content: Upload photos or other files created by your users to Cloud Storage.
  • File downloads: Download files to the local file system on Android and iOS or as a Blob on the Web.
  • Content delivery: Retrieve the download URL of a file to display or share it.
  • File management: List the files in a directory, read and update their metadata, or delete them.

Compatibility

Plugin VersionCapacitor VersionStatus
8.x.x>=8.x.xActive support
7.x.x7.x.xDeprecated
6.x.x6.x.xDeprecated

Guides

Installation

You can use our AI-Assisted Setup to install the plugin. Add the Capawesome Skills to your AI tool using the following command:

npx skills add capawesome-team/skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capacitor-firebase/storage` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capacitor-firebase/storage
npx cap sync

Add Firebase to your project if you haven't already (Android / iOS).

Android

Variables

If needed, you can define the following project variable in your app’s variables.gradle file to change the default version of the dependency:

  • $firebaseStorageVersion version of com.google.firebase:firebase-storage (default: 22.0.1)

This can be useful if you encounter dependency conflicts with other plugins in your project.

iOS

Swift Package Manager

Add the following to your capacitor.config.json (or capacitor.config.ts) to avoid a SwiftPM package identity collision:

{
  "experimental": {
    "ios": {
      "spm": {
        "packageOptions": {
          "@capacitor-firebase/storage": {
            "symlink": true
          }
        }
      }
    }
  }
}

Attention: SPM packageOptions support requires Capacitor CLI 8.4.0+.

Configuration

No configuration required for this plugin.

Demo

A working example can be found here: robingenz/capacitor-firebase-plugin-demo

Starter templates

The following starter templates are available:

Usage

The following examples show how to upload and download files, get a download URL, list files, read and update file metadata, delete files, and connect to the Cloud Storage emulator.

Upload a file

Upload a file to Cloud Storage. On Android and iOS, provide the uri to the file to upload. On the Web, provide the data to upload as a Blob using the blob option instead. The callback is invoked with the upload progress and with completed set to true once the upload is finished:

import { FirebaseStorage } from '@capacitor-firebase/storage';

const uploadFile = async () => {
  return new Promise((resolve, reject) => {
    FirebaseStorage.uploadFile(
      {
        path: 'images/mountains.png',
        uri: 'file:///var/mobile/Containers/Data/Application/E397A70D-67E4-4258-236E-W1D9E12111D4/Library/Caches/092F8464-DE60-40B3-8A23-EB83160D9F9F/mountains.png',
      },
      (event, error) => {
        if (error) {
          reject(error);
        } else if (event?.completed) {
          resolve();
        }
      }
    );
  });
};

Download a file

Download a file from Cloud Storage. On Android and iOS, the file is downloaded to the local file system using the uri option. On the Web, the downloaded file is returned as a Blob in the callback event:

import { FirebaseStorage } from '@capacitor-firebase/storage';

const downloadFileWithFirebaseStorage = async () => {
  return new Promise((resolve, reject) => {
    FirebaseStorage.downloadFile(
      {
        path: 'images/mountains.png',
        uri: 'file:///var/mobile/Containers/Data/Application/E397A70D-67E4-4258-236E-W1D9E12111D4/Library/Caches/mountains.png', // Only available for Android and iOS
      },
      (event, error) => {
        if (error) {
          reject(error);
        } else if (event?.completed) {
          // On Web, the downloaded file is available as a Blob in event.blob
          resolve(event?.blob);
        }
      }
    );
  });
};

Download a file with the Filesystem plugin

Alternatively, you can retrieve the download URL of the file and download it using the official Capacitor Filesystem plugin:

import { FirebaseStorage } from '@capacitor-firebase/storage';
import { Filesystem, Directory } from '@capacitor/filesystem';

const downloadFileWithFilesystem = async () => {
  const { downloadUrl } = await FirebaseStorage.getDownloadUrl({
    path: 'images/mountains.png',
  });
  const { path } = await Filesystem.downloadFile({
    url: downloadUrl,
    path: 'mountains.png',
    directory: Directory.Cache,
  });
  return path;
};

Get a download URL

Retrieve the download URL of a file, for example to display or share it:

import { FirebaseStorage } from '@capacitor-firebase/storage';

const getDownloadUrl = async () => {
  const { downloadUrl } = await FirebaseStorage.getDownloadUrl({
    path: 'images/mountains.png',
  });
  return downloadUrl;
};

List files in a directory

List the files in a directory. Use the maxResults and pageToken options to paginate through large directories:

import { FirebaseStorage } from '@capacitor-firebase/storage';

const listFiles = async () => {
  const { items } = await FirebaseStorage.listFiles({
    path: 'images',
  });
  return items;
};

Read and update file metadata

Read the metadata of a file, such as its size, content type, and timestamps, or update it, including user-defined custom metadata:

import { FirebaseStorage } from '@capacitor-firebase/storage';

const getMetadata = async () => {
  const result = await FirebaseStorage.getMetadata({
    path: 'images/mountains.png',
  });
  return result;
};

const updateMetadata = async () => {
  await FirebaseStorage.updateMetadata({
    path: 'images/mountains.png',
    metadata: {
      contentType: 'image/png',
      customMetadata: {
        foo: 'bar',
      },
    },
  });
};

Delete a file

Delete a file from Cloud Storage:

import { FirebaseStorage } from '@capacitor-firebase/storage';

const deleteFile = async () => {
  await FirebaseStorage.deleteFile({
    path: 'images/mountains.png',
  });
};

Use the Cloud Storage emulator

During development, you can instrument your app to talk to the local Cloud Storage emulator. When using an Android emulator device, 10.0.2.2 is the special IP address to connect to the localhost of the host computer. Note that on Android, the cleartext traffic must be allowed, which is not intended for use in production:

import { FirebaseStorage } from '@capacitor-firebase/storage';

const useEmulator = async () => {
  await FirebaseStorage.useEmulator({
    host: '10.0.2.2',
    port: 9001,
  });
};

API

deleteFile(...)

deleteFile(options: DeleteFileOptions) => Promise<void>

Delete a file.

ParamType
optionsDeleteFileOptions

Since: 5.3.0


getDownloadUrl(...)

getDownloadUrl(options: GetDownloadUrlOptions) => Promise<GetDownloadUrlResult>

Get the download url for a file.

ParamType
optionsGetDownloadUrlOptions

Returns: Promise<GetDownloadUrlResult>

Since: 5.3.0


getMetadata(...)

getMetadata(options: GetMetadataOptions) => Promise<GetMetadataResult>

Get the metadata for a file.

ParamType
optionsGetMetadataOptions

Returns: Promise<GetMetadataResult>

Since: 5.3.0


listFiles(...)

listFiles(options: ListFilesOptions) => Promise<ListFilesResult>

List files in a directory.

ParamType
optionsListFilesOptions

Returns: Promise<ListFilesResult>

Since: 5.3.0


updateMetadata(...)

updateMetadata(options: UpdateMetadataOptions) => Promise<void>

Update the metadata for a file.

ParamType
optionsUpdateMetadataOptions

Since: 5.3.0


downloadFile(...)

downloadFile(options: DownloadFileOptions, callback: DownloadFileCallback) => Promise<CallbackId>

Download a file.

On Android and iOS, the file is downloaded to the local file system using the uri option.

On Web, the file is downloaded as a Blob and returned in the callback event.

ParamType
optionsDownloadFileOptions
callbackDownloadFileCallback

Returns: Promise<string>

Since: 8.2.0


uploadFile(...)

uploadFile(options: UploadFileOptions, callback: UploadFileCallback) => Promise<CallbackId>

Upload a file.

ParamType
optionsUploadFileOptions
callbackUploadFileCallback

Returns: Promise<string>

Since: 5.3.0


useEmulator(...)

useEmulator(options: UseEmulatorOptions) => Promise<void>

Instrument your app to talk to the Cloud Storage emulator.

On Android, the cleartext traffic must be allowed. On the Capacitor configuration:

{
  server: {
    cleartext: true
  }
}

The cleartext traffic is not intended for use in production.

ParamType
optionsUseEmulatorOptions

Since: 6.1.0


Interfaces

DeleteFileOptions

PropTypeDescriptionSince
pathstringThe full path to the file to delete, including the file name.5.3.0

GetDownloadUrlResult

PropTypeDescriptionSince
downloadUrlstringThe download url for the file.5.3.0

GetDownloadUrlOptions

PropTypeDescriptionSince
pathstringThe full path to the file to get the download url for, including the file name.5.3.0

GetMetadataResult

PropTypeDescriptionSince
bucketstringThe bucket this file is contained in.5.3.0
createdAtnumberThe timestamp at which the file was created in milliseconds since the epoch.5.3.0
generationstringThe object's generation.5.3.0
md5HashstringThe md5 hash of the file.5.3.0
metadataGenerationstringThe object's metadata generation.5.3.0
namestringThe short name of this file, which is the last component of the full path.5.3.0
pathstringThe full path to the file, including the file name.5.3.0
sizenumberThe size of the file in bytes.5.3.0
updatedAtnumberThe timestamp at which the file was last updated in milliseconds since the epoch.5.3.0
cacheControlstringServed as the Cache-Control header on object download.6.1.0
contentDispositionstringServed as the Content-Disposition header on object download.6.1.0
contentEncodingstringServed as the Content-Encoding header on object download.6.1.0
contentLanguagestringServed as the Content-Language header on object download.6.1.0
contentTypestringServed as the Content-Type header on object download.6.1.0
customMetadata{ [key: string]: string; }Additional user-defined custom metadata.6.1.0

GetMetadataOptions

PropTypeDescriptionSince
pathstringThe full path to the file to get the metadata for, including the file name.5.3.0

ListFilesResult

PropTypeDescriptionSince
itemsStorageReference[]The list of files in the directory.5.3.0
nextPageTokenstringIf set, there might be more results for this list. Use this token to resume the list.5.3.0

StorageReference

PropTypeDescriptionSince
bucketstringThe bucket this file is contained in.5.3.0
pathstringThe full path to the file, including the file name.5.3.0
namestringThe short name of this file, which is the last component of the full path.5.3.0

ListFilesOptions

PropTypeDescriptionDefaultSince
pathstringThe full path to the directory to list files for.5.3.0
maxResultsnumberThe maximum number of results to return.10005.3.0
pageTokenstringThe page token, returned by a previous call to this method. If provided, listing is resumed from the previous position.5.3.0

UpdateMetadataOptions

PropTypeDescriptionSince
pathstringThe full path to the file to update the metadata for, including the file name.5.3.0
metadataSettableMetadataThe metadata to update.5.3.0

SettableMetadata

PropTypeDescriptionSince
cacheControlstringServed as the Cache-Control header on object download.5.3.0
contentDispositionstringServed as the Content-Disposition header on object download.5.3.0
contentEncodingstringServed as the Content-Encoding header on object download.5.3.0
contentLanguagestringServed as the Content-Language header on object download.5.3.0
contentTypestringServed as the Content-Type header on object download.5.3.0
customMetadata{ [key: string]: string; }Additional user-defined custom metadata.5.3.0

DownloadFileOptions

PropTypeDescriptionSince
pathstringThe full path to the file to download, including the file name.8.2.0
uristringThe uri to download the file to. Only available for Android and iOS.8.2.0

DownloadFileCallbackEvent

PropTypeDescriptionSince
progressnumberThe download progress, as a percentage between 0 and 1.8.2.0
bytesTransferrednumberThe number of bytes that have been transferred. Only available for Android and Web.8.2.0
totalBytesnumberThe total number of bytes to be transferred. Only available for Android and Web.8.2.0
completedbooleanWhether the download is completed or not.8.2.0
blobBlobThe downloaded file as a Blob. Only available for Web.8.2.0

UploadFileOptions

PropTypeDescriptionSince
blobBlobThe data to upload. Only available for Web.5.3.0
pathstringThe full path where data should be uploaded, including the file name.5.3.0
uristringThe uri to the file to upload. Only available for Android and iOS.5.3.0
metadataUploadMetadataThe metadata to set for the file.5.4.0

UploadMetadata

PropTypeDescriptionSince
md5HashstringThe base64-encoded MD5 hash of the file. Only available for Web.5.4.0

UploadFileCallbackEvent

PropTypeDescriptionSince
progressnumberThe upload progress, as a percentage between 0 and 1.5.3.0
bytesTransferrednumberThe number of bytes that have been transferred. Only available for Android and Web.5.3.0
totalBytesnumberThe total number of bytes to be transferred. Only available for Android and Web.5.3.0
completedbooleanWhether the upload is completed or not.5.3.0

UseEmulatorOptions

PropTypeDescriptionDefaultSince
hoststringThe emulator host without any port or scheme. Note when using a Android Emulator device: 10.0.2.2 is the special IP address to connect to the 'localhost' of the host computer.6.1.0
portnumberThe emulator port.91996.1.0

Type Aliases

DownloadFileCallback

(event: DownloadFileCallbackEvent | null, error: any): void

CallbackId

string

UploadFileCallback

(event: UploadFileCallbackEvent | null, error: any): void

FAQ

How do I track the progress of an upload or download?

The uploadFile(...) and downloadFile(...) methods accept a callback that is invoked with events containing the progress as a fraction between 0 and 1 and a completed flag. The bytesTransferred and totalBytes properties are only available on Android and Web.

How does downloading a file differ between the platforms?

On Android and iOS, the file is downloaded to the local file system using the uri option. On the Web, the downloaded file is returned as a Blob in the callback event. Alternatively, you can retrieve the download URL with getDownloadUrl(...) and download the file with the official Capacitor Filesystem plugin, as shown in the usage example above.

How do I upload a file selected by the user?

On Android and iOS, pass the uri of the file to the uploadFile(...) method. On the Web, pass the data as a Blob using the blob option instead. You can use the File Picker plugin to let the user select a file on the device.

How can I store additional information about a file?

You can set metadata for a file when uploading it using the metadata option or update it later with updateMetadata(...), including user-defined key-value pairs via customMetadata. Use getMetadata(...) to read the metadata of a file, such as its size, content type, and timestamps.

Can I test against the Cloud Storage emulator?

Yes, use the useEmulator(...) method to instrument your app to talk to the local Cloud Storage emulator, as shown in the usage example above. When testing on an Android emulator device, use 10.0.2.2 as the host to reach the localhost of the host computer. Keep in mind that on Android, the cleartext traffic must be allowed for this, which is not intended for use in production.

Newsletter

Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our Capawesome Newsletter.

Changelog

See CHANGELOG.md.

License

See LICENSE.

[^1]: This project is not affiliated with, endorsed by, sponsored by, or approved by Google LLC or any of their affiliates or subsidiaries.

版本与发布记录

@capacitor-firebase/storage 共发布 31 个版本,首次发布于 2023/10/15;过去 12 个月发布了 13 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.6.0latest2026/10/319 天前
8.5.22026/09/171 个月前
8.5.12026/09/022 个月前
8.5.02026/08/312 个月前
8.4.02026/08/122 个月前
8.3.02026/06/045 个月前

其他发布通道:dev → 7.0.0-dev.1765887457。

关于 @capacitor-firebase/storage 的常见问题

@capacitor-firebase/storage 是什么?

Capacitor plugin for Firebase Cloud Storage on Android, iOS, and Web.

如何安装 @capacitor-firebase/storage?

在项目目录运行 npm install @capacitor-firebase/storage,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capacitor-firebase/storage 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capacitor-firebase/storage 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capacitor-firebase/storage 可以商用吗?

@capacitor-firebase/storage 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@capacitor-firebase/storage 的下载量有多少?

根据 npm 官方下载统计,@capacitor-firebase/storage 在 2026/10/09 – 2026/11/07 这 30 天内被下载 10,931 次,日均约 364 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capacitor-firebase/storage 还在维护吗?

最新版本 8.6.0 发布于 2026/10/31(9 天前);至今共发布 31 个版本,其中过去 12 个月发布了 13 个;首次发布于 2023/10/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。