Firebase Storage support for Android & iOS
Npm
npm install @bazumax/capacitor-firebase-storage
npx cap sync
Yarn
yarn add @bazumax/capacitor-firebase-storage
npx cap sync
Call uploadFile
to open image picker and upload image to Storage
import {FirebaseStorage} from "@bazumax/capacitor-firebase-storage"
const event = await FirebaseStorage.addListener('onUploadStateChanged', async ({state}) => {
const messages = {
"compressing": "Compressing...",
"uploading": "Uploading to Firebase...",
}
console.log("[FirebaseStorage] state: " + messages[state])
})
try {
const { url } = await FirebaseStorage.uploadFile({
withImagePicker: true,
title: "Select avatar",
storagePath: `/users/avatars/${state.uid}`,
compress: true
})
// Do anymore with public url
// ....
} finally {
// Unsubscribe event when all work done!
event.remove()
}
uploadFile(...)
deleteFile(...)
getDownloadUrl(...)
watchFileCreation(...)
addListener(string, ...)
removeAllListeners()
- Interfaces
- Type Aliases
uploadFile(options: UploadFileOptions) => Promise<UploadFileResults>
Param | Type |
---|---|
options |
UploadFileOptions |
Returns: Promise<UploadFileResults>
deleteFile(options: { path: string; }) => Promise<{ message: string; }>
Param | Type |
---|---|
options |
{ path: string; } |
Returns: Promise<{ message: string; }>
getDownloadUrl(options: { path: string; }) => Promise<{ url: string; }>
Param | Type |
---|---|
options |
{ path: string; } |
Returns: Promise<{ url: string; }>
watchFileCreation(options: { path: string; }) => Promise<{ url: string; }>
Param | Type |
---|---|
options |
{ path: string; } |
Returns: Promise<{ url: string; }>
addListener(eventName: string, listenerFunc: ListenerCallback) => Promise<PluginListenerHandle> & PluginListenerHandle
Param | Type |
---|---|
eventName |
string |
listenerFunc |
ListenerCallback |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
removeAllListeners() => Promise<void>
Prop | Type |
---|---|
url |
string |
Prop | Type |
---|---|
withImagePicker |
boolean |
title |
string |
storagePath |
string |
Prop | Type |
---|---|
remove |
() => Promise<void> |
(err: any, ...args: any[]): void