{"id":18369822,"url":"https://github.com/cawfree/react-native-firebase-upload-provider","last_synced_at":"2025-04-06T18:32:32.960Z","repository":{"id":44005298,"uuid":"237416525","full_name":"cawfree/react-native-firebase-upload-provider","owner":"cawfree","description":"📸 Easily and quickly upload rich media to Firebase Storage.","archived":false,"fork":false,"pushed_at":"2023-01-05T06:11:16.000Z","size":1355,"stargazers_count":7,"open_issues_count":11,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T11:39:01.021Z","etag":null,"topics":["firebase","helper","react","react-native","storage","uploader"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cawfree.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-31T11:26:59.000Z","updated_at":"2023-09-07T06:20:13.000Z","dependencies_parsed_at":"2023-02-03T15:01:32.613Z","dependency_job_id":null,"html_url":"https://github.com/cawfree/react-native-firebase-upload-provider","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cawfree%2Freact-native-firebase-upload-provider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cawfree%2Freact-native-firebase-upload-provider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cawfree%2Freact-native-firebase-upload-provider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cawfree%2Freact-native-firebase-upload-provider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cawfree","download_url":"https://codeload.github.com/cawfree/react-native-firebase-upload-provider/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247531319,"owners_count":20953934,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["firebase","helper","react","react-native","storage","uploader"],"created_at":"2024-11-05T23:32:21.248Z","updated_at":"2025-04-06T18:32:31.225Z","avatar_url":"https://github.com/cawfree.png","language":"JavaScript","funding_links":["https://www.buymeacoffee.com/cawfree"],"categories":[],"sub_categories":[],"readme":"# react-native-firebase-upload-provider\nEasily and quickly upload rich media to Firebase Storage. This library safely handles all of the lower level firebase storage transactions, whilst providing a sensible interface to synchronize your frontend with the transaction state.\n\n\u003ca href=\"#badge\"\u003e\n    \u003cimg alt=\"code style: prettier\" src=\"https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square\"\u003e\n\u003c/a\u003e\n\n\u003cbr /\u003e\n\u003cbr /\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./public/image.jpg\" width=\"640\" height=\"360\" /\u003e\n\u003c/p\u003e\n\n## 🚀 Getting Started \n\nUsing [`npm`]():\n\n```shell\nnpm install --save react-native-firebase-upload-provider\n```\n\nUsing [`yarn`]():\n\n```shell\nyarn add react-native-firebase-upload-provider\n```\n\n## 📋 Prerequisites\n\n  - Make sure you've added the `google-services.json` and `GoogleService-Info.plist` to your `*/android/app/` and `*/ios/` directories respectively.\n    - If this sounds new to you, it would be worth checking out the [Getting Started](https://rnfirebase.io/docs/v5.x.x/getting-started) tutorials on [react-native-firebase](https://rnfirebase.io/).\n  - Once your project is hooked up, head over to your project in [Firebase](https://firebase.google.com/) and make sure you've [enabled Firebase Storage](https://firebase.google.com/docs/storage/web/start).\n  - Finally, you'll need to make sure your application has the appropriate permissions to write to the storage bucket.\n    - By default, they do not permit anything to be written. For testing purposes, you can go ahead and turn `false` into `true` to permit anyone to read and write.\n\n```diff\nrules_version = '2';\nservice firebase.storage {\n  match /b/{bucket}/o {\n    match /{allPaths=**} {\n-      allow read, write: if false;\n+      allow read, write: if true;\n    }\n  }\n}\n\n```\n\u003e ⚠️   **Note**: This is not a safe configuration to use within a production environment.\n\n## ✍️ Usage\n\n### 1. First, wrap your application with the `FirebaseUploadProvider`:\n\n```javascript\nimport React from 'react';\nimport { Text } from 'react-native';\nimport FirebaseUploadProvider from 'react-native-firebase-upload-provider';\n\nexport default () =\u003e (\n  \u003cFirebaseUploadProvider\n    supportedMimeTypes={[\n      \"image/png\",\n      \"image/jpeg\"\n    ]}\n  \u003e\n    \u003cText\n      children=\"Best app ever.\"\n    /\u003e\n  \u003c/FirebaseUploadProvider\u003e\n);\n```\n\nThis provides all of the data dependencies required to perform a file upload from basically anywhere in your application. In particular, notice that we're required to specify which [Mime Types](https://www.npmjs.com/package/mime-types) are permitted to be uploaded to your [Storage Bucket](https://cloud.google.com/storage/docs/creating-buckets). By default, no mime types are specified as a safeguard to prevent any users from uploading potentially undesirable content.\n\n### 2. Next, there are the [hooks](https://reactjs.org/docs/hooks-intro.html). There are two you'll be interested in:\n\n```javascript\nimport { useFirebaseUploads } from 'react-native-firebase-upload-provider';\n\nconst UploadButton = ({ ...extraProps }) =\u003e {\n  const { useUploads, requestUpload } = useFirebaseUploads();\n  return ...;\n}\n```\n\n#### 2.1 `requestUpload(uri)`\n\n  This hook is used to upload an asset from the local filesystem up to firebase. It is a **synchronous** call, which when invoked returns an array with the following shape:\n\n```javascript\nconst [uploadId, beginUpload] = requestUpload('file://path/to/some/asset.jpeg');\n```\n  \n  The `uploadId` is an internal [`uuidv4`](https://www.npmjs.com/package/uuid) which is used to uniquely track the transaction of the specified file, whilst `beginUpload` is a function which when invoked attempts to start the transaction, or restart the transaction if it had previously failed.\n\n  Upon completion, `beginUpload` resolves with the raw transaction, i.e. you can make a call to `getDownloadURL()` or `getMetadata()`.\n\n#### 2.2 `useUploads()`\n\n  This hook allows you to interrogate the state of the ongoing transactions, and have your registered component re-render when any of the transactions have been updated. This is how we can determine things like the state of the task, the number of `bytesTransferred` and the `totalNumberOfBytes`, etc.\n\n```javascript\nconst { useUploads } = useFirebaseUploads();\nconst uploads = useUploads();\nreturn (\n  \u003cText\n    children={JSON.stringify(uploads)}\n  /\u003e\n);\n```\n\n  This allows you to easily synchronize the interface presented to your user with the ongoing transaction.\n\n## ✌️ License\n[MIT](https://opensource.org/licenses/MIT)\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.buymeacoffee.com/cawfree\"\u003e\n    \u003cimg src=\"https://cdn.buymeacoffee.com/buttons/default-orange.png\" alt=\"Buy @cawfree a coffee\" width=\"232\" height=\"50\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcawfree%2Freact-native-firebase-upload-provider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcawfree%2Freact-native-firebase-upload-provider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcawfree%2Freact-native-firebase-upload-provider/lists"}