6.0.0 • Published 23 days ago

@capacitor-firebase/storage v6.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
23 days ago

@capacitor-firebase/storage

Unofficial Capacitor plugin for Firebase Cloud Storage.^1

Installation

npm install @capacitor-firebase/storage
npx cap sync

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

Android

Variables

This plugin will use the following project variables (defined in your app’s variables.gradle file):

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

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

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

const uploadFile = async () => {
  return new Promise((resolve, reject) => {
    await 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();
        }
      }
    );
  });
};

const downloadFile = 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;
};

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

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

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

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',
      },
    },
  });
};

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


uploadFile(...)

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

Upload a file.

ParamType
optionsUploadFileOptions
callbackUploadFileCallback

Returns: Promise<string>

Since: 5.3.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

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

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

Type Aliases

UploadFileCallback

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

CallbackId

string

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.

6.0.0

23 days ago

5.4.1

3 months ago

5.4.0

4 months ago

5.3.0

5 months ago