{"id":21239215,"url":"https://github.com/tinacious/react-native-save-base-sixty-four","last_synced_at":"2025-07-10T19:32:13.200Z","repository":{"id":57339701,"uuid":"324433123","full_name":"tinacious/react-native-save-base-sixty-four","owner":"tinacious","description":"Allows you to save a base64-encoded image to your Photos or share it via the native share sheet.","archived":false,"fork":false,"pushed_at":"2020-12-28T01:12:51.000Z","size":1150,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-03T12:41:21.881Z","etag":null,"topics":["android","base64","ios","kotlin","react-native","swift","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/tinacious.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-25T21:05:40.000Z","updated_at":"2022-05-11T15:38:17.000Z","dependencies_parsed_at":"2022-09-04T14:23:28.927Z","dependency_job_id":null,"html_url":"https://github.com/tinacious/react-native-save-base-sixty-four","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/tinacious/react-native-save-base-sixty-four","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinacious%2Freact-native-save-base-sixty-four","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinacious%2Freact-native-save-base-sixty-four/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinacious%2Freact-native-save-base-sixty-four/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinacious%2Freact-native-save-base-sixty-four/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tinacious","download_url":"https://codeload.github.com/tinacious/react-native-save-base-sixty-four/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinacious%2Freact-native-save-base-sixty-four/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264396783,"owners_count":23601553,"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":["android","base64","ios","kotlin","react-native","swift","typescript"],"created_at":"2024-11-21T00:42:28.714Z","updated_at":"2025-07-10T19:32:12.595Z","avatar_url":"https://github.com/tinacious.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-save-base-sixty-four\n\nAllows you to save a base64-encoded image to your Photos or share it via the native share sheet.\n\n- [About this module](#about-this-module)\n  - [Android support](#android-support)\n  - [iOS support](#ios-support)\n- [Installation](#installation)\n  - [iOS](#ios)\n  - [Android](#android)\n- [Usage](#usage)\n  - [`share(base64ImageString: string, options: SaveBase64ImageOptions)`](#sharebase64imagestring-string-options-savebase64imageoptions)\n  - [`save(base64ImageString: string, options: SaveBase64ImageOptions)`](#savebase64imagestring-string-options-savebase64imageoptions)\n  - [`base64ImageString: string`](#base64imagestring-string)\n  - [`options: SaveBase64ImageOptions`](#options-savebase64imageoptions)\n  - [Managing Permissions](#managing-permissions)\n- [Contributing](#contributing)\n- [License](#license)\n\n\n## About this module\n\nThis module was developed specifically for working with base64 encoded images, with an emphasis on Android support.\n\nIf you are **only** looking for share sheet functionality, I would recommend using [react-native-share](https://github.com/react-native-share/react-native-share). It supports base64 strings out of the box with no additional work.\n\nIf you are looking for the ability to save a base64 string to the camera roll, specifically with support for the current version of Android as well as legacy versions of Android, this module will help you with that.\n\nIf you want to read more about why I developed this module, you can read the [blog post](https://blog.tinaciousdesign.com/save-to-photos-gallery-android-10-android-q).\n\n\n### Android support\n\nThis module provides support for:\n\n- Scoped storage in Android Q\n- Legacy storage in versions of Android older than Q\n\nPlease also note the permission checking in the example app as requesting and verifying permissions differs between Q and older versions of Android.\n\nWhen a user does not accept permissions, a few things happen:\n\n- On Android Q and above:\n  - The user can share via the share sheet\n  - Saving to device is successful\n- On older versions of Android:\n  - Sharing via the share sheet crashes due to lack of permission\n  - Saving to device crashes due to lack of permission\n\nFor the above reasons, it's recommended to check for permissions on Android before performing any operations that require them, specifically on older versions of Android. See the **Managing Permissions** section below for an example.\n\n\n### iOS support\n\nWhen a user does not accept permissions:\n\n- When attempting to share via the share sheet:\n  - Sharing is successful (no permissions required for this action)\n- When attempting to save:\n  - The promise will resolve with a value of `false` so you can handle the failure as expected due to the user not granting permission\n\n\n## Installation\n\n```sh\nnpm install react-native-save-base-sixty-four --save\nyarn add react-native-save-base-sixty-four\n```\n\n### iOS\n\nAdd this to your `Info.plist`:\n\n```xml\n\u003ckey\u003eNSPhotoLibraryAddUsageDescription\u003c/key\u003e\n\u003cstring\u003eSave photo to device\u003c/string\u003e\n```\n\nThe `\u003cstring\u003e` value above can be anything you like—this will be the message that shows up when the user is prompted to allow photo access.\n\n### Android\n\nAdd this to your `AndroidManifest.xml`:\n\n```xml\n\u003cuses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\" /\u003e\n\u003cuses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"\n    android:maxSdkVersion=\"28\" /\u003e\n```\n\n## Usage\n\nCall either the `share` or `save` method with the base64 encoded string and optional options for Android.\n\n### `share(base64ImageString: string, options: SaveBase64ImageOptions)`\n\n```js\nimport SaveBase64Image from 'react-native-save-base-sixty-four';\n\n// Native share sheet\n//    with async await\ntry {\n  const success = await SaveBase64Image.share(base64ImageString, options);\n  if (!success) {\n    // 😭 user did not grant permission\n  }\n} catch (error) {\n  // 💥 there was a crash\n}\n\n//    with promises\nSaveBase64Image\n  .share(base64ImageString, options)\n  .then((success) =\u003e {\n    if (!success) {\n      // 😭 user did not grant permission\n    }\n  })\n  .catch((error) =\u003e {\n    // 💥 there was a crash\n  });\n```\n\n### `save(base64ImageString: string, options: SaveBase64ImageOptions)`\n\n```js\nimport SaveBase64Image from 'react-native-save-base-sixty-four';\n\n// Save to device\n//    with async await\ntry {\n  const success = await SaveBase64Image.save(base64ImageString, options);\n  if (!success) {\n    // 😭 user did not grant permission\n  }\n} catch (error) {\n  // 💥 there was a crash\n}\n\n//    with promises\nSaveBase64Image\n  .save(base64ImageString, options)\n  .then((success) =\u003e {\n    if (!success) {\n      // 😭 user did not grant permission\n    }\n  })\n  .catch((error) =\u003e {\n    // 💥 there was a crash\n  });\n```\n\n\n### `base64ImageString: string`\n\nThe base64 encoded string should **not** have the header, i.e. `data:image/png;base64,` (or similar) should be removed.\n\n\n### `options: SaveBase64ImageOptions`\n\nThe options below are used in the Android module:\n\n```ts\ninterface SaveBase64ImageOptions {\n  mimeType?: 'image/png' | 'image/jpg';\n  quality?: number;\n  fileName?: string;\n}\n```\n\n- **`mimeType`** `(default: 'image/png')`: Android configuration of mime type for bitmap compression and for the share intent. Currently only supporting `'image/png' | 'image/jpg'`\n- **`quality`** `(default: 100)`: Bitmap compression quality on Android\n- **`fileName`** `(default: 'image'`): The filename for Android. This will be visible in the Photos app when saving and as the file name when sharing.\n\n\n### Managing Permissions\n\nHere's an example implementation that uses the permissions code in the example app:\n\n```js\nconst handleBase64Image = async (base64ImageString, fileName) =\u003e {\n  const imageWithoutHeader = base64ImageString.replace('data:image/png;base64,', '');\n\n  if (Platform.OS === 'android') {\n    const hasPermission = await hasStoragePermissions();\n    if (!hasPermission) {\n      Alert.alert('Fail', 'You need to give the app permission');\n      return;\n    }\n  }\n\n  const success = await SaveBase64Image.save(imageWithoutHeader, { fileName });\n  Alert.alert(success ? '😄 Success' : '😞 Fail');\n};\n```\n\n\n## Contributing\n\nSee the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinacious%2Freact-native-save-base-sixty-four","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinacious%2Freact-native-save-base-sixty-four","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinacious%2Freact-native-save-base-sixty-four/lists"}