{"id":31244422,"url":"https://github.com/RonRadtke/react-native-blob-util","last_synced_at":"2025-09-23T02:04:22.273Z","repository":{"id":37374462,"uuid":"330133141","full_name":"RonRadtke/react-native-blob-util","owner":"RonRadtke","description":"A project committed to making file access and data transfer easier, efficient for React Native developers.","archived":false,"fork":true,"pushed_at":"2025-09-06T08:07:30.000Z","size":91409,"stargazers_count":866,"open_issues_count":95,"forks_count":157,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-09-06T10:07:28.886Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"joltup/rn-fetch-blob","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RonRadtke.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":"2021-01-16T10:04:35.000Z","updated_at":"2025-09-06T08:07:36.000Z","dependencies_parsed_at":"2023-02-15T13:46:00.152Z","dependency_job_id":null,"html_url":"https://github.com/RonRadtke/react-native-blob-util","commit_stats":null,"previous_names":[],"tags_count":128,"template":false,"template_full_name":null,"purl":"pkg:github/RonRadtke/react-native-blob-util","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RonRadtke%2Freact-native-blob-util","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RonRadtke%2Freact-native-blob-util/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RonRadtke%2Freact-native-blob-util/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RonRadtke%2Freact-native-blob-util/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RonRadtke","download_url":"https://codeload.github.com/RonRadtke/react-native-blob-util/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RonRadtke%2Freact-native-blob-util/sbom","scorecard":{"id":122600,"data":{"date":"2025-08-11","repo":{"name":"github.com/RonRadtke/react-native-blob-util","commit":"3e247b54eefa41026d44d18cae8de3a2f55c3e76"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.8,"checks":[{"name":"Code-Review","score":3,"reason":"Found 3/8 approved changesets -- score normalized to 3","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":10,"reason":"30 commit(s) and 5 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/npm_publish.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":9,"reason":"binaries present in source code","details":["Warn: binary detected: android/gradle/wrapper/gradle-wrapper.jar:1"],"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Pinned-Dependencies","score":3,"reason":"dependency not pinned by hash detected -- score normalized to 3","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm_publish.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/RonRadtke/react-native-blob-util/npm_publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm_publish.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/RonRadtke/react-native-blob-util/npm_publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm_publish.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/RonRadtke/react-native-blob-util/npm_publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm_publish.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/RonRadtke/react-native-blob-util/npm_publish.yml/master?enable=pin","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   2 out of   2 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 25 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"24 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-76c9-3jph-rj3q","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh","Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg","Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p","Warn: Project is vulnerable to: GHSA-g4rg-993r-mgx7","Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6","Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-16T02:50:49.444Z","repository_id":37374462,"created_at":"2025-08-16T02:50:49.444Z","updated_at":"2025-08-16T02:50:49.444Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276502702,"owners_count":25653733,"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","status":"online","status_checked_at":"2025-09-23T02:00:09.130Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-09-23T02:01:24.995Z","updated_at":"2025-09-23T02:04:22.261Z","avatar_url":"https://github.com/RonRadtke.png","language":"Java","funding_links":[],"categories":["二、核心开发工具与库（按场景分类）"],"sub_categories":["8. 后端与网络"],"readme":"# react-native-blob-util\n\n[![release](https://img.shields.io/github/release/RonRadtke/react-native-blob-util.svg?style=flat-square)](https://github.com/RonRadtke/react-native-blob-util/releases) [![npm](https://img.shields.io/npm/v/react-native-blob-util.svg?style=flat-square)](https://www.npmjs.com/package/react-native-blob-util) ![](https://img.shields.io/badge/PR-Welcome-brightgreen.svg?style=flat-square) [![](https://img.shields.io/badge/Wiki-Public-brightgreen.svg?style=flat-square)](https://github.com/RonRadtke/react-native-blob-util/wiki) [![npm](https://img.shields.io/npm/l/react-native-blob-util.svg?maxAge=2592000\u0026style=flat-square)]()\n\nA project committed to making file access and data transfer easier and more efficient for React Native developers.\n\n# I forked this project to continue working on it.\n\nThis project is a fork of https://www.npmjs.com/package/rn-fetch-blob which on the other hand is a fork of https://github.com/wkh237/react-native-fetch-blob. Both the original repository and its first fork are not maintained anymore.\n\nThe project will be continued in this repository. React-Native-Blob-Util is fully compatible with RN-Fetch-Blob and React-Native-Fetch-Blob. If you want to support the project feel free to contact me or create a pull request with your feature.\n\n# Version Compatibility Warning\n\nreact-native-blob-util version **0.22.0** and up is only compatible with react native **0.76** and up.\n\"0.22.0\" -\u003e 0.76 RN\n\"0.22.1\" -\u003e 0.77 RN\n\"0.22.2\" -\u003e 0.78 RN\n\nreact-native-blob-util version **0.17.0** and up is only compatible with react native **0.65** and up.\n\nreact-native-blob-util version **0.10.16** and up is only compatible with react native **0.60** and up.\n\n## Features\n\n- Access and write data to Android Media Store (e.g. Downloads folder on devices \u003e Android 9)\n- Transfer data directly from/to storage without BASE64 bridging\n- File API supports regular files, Asset files, and CameraRoll files\n- Native-to-native file manipulation API, reduce JS bridging performance loss\n- File stream support for dealing with large file\n- Blob, File, XMLHttpRequest polyfills that make browser-based library available in RN (experimental)\n- JSON stream supported base on [Oboe.js](https://github.com/jimhigson/oboe.js/) @jimhigson\n\n## React Native New Architecture\nWith React Native 0.68.0 the switch to enable the new aritechture was introduced.\nStarting with version 0.17.0 this library introduces support for the new architecture as well. Of course the old architecture will still be supported.\nFurther information about it and how to use it you can find here: https://reactnative.dev/docs/next/the-new-architecture/landing-page\n\n## Android 10 \u0026 11\n\nAndroid 10 introduced scoped storage for apps. Apps no longer can create own directories directly on the external storage or access files outside the apps own directories. With version 0.14.0 support for the media storage is implemented. For more information please see the chapter about the mediastore API.\n[test](###android-media-storage)\nFor more information see: https://developer.android.com/training/data-storage\n\n## TOC (visit [Wiki](https://github.com/RonRadtke/react-native-blob-util/wiki) to get the complete documentation)\n\n* [About](#user-content-about)\n* [Installation](#user-content-installation)\n* [HTTP Data Transfer](#user-content-http-data-transfer)\n* [Regular Request](#user-content-regular-request)\n* [Download file](#download-example-fetch-files-that-need-authorization-token)\n* [Upload file](#user-content-upload-example--dropbox-files-upload-api)\n* [Multipart/form upload](#user-content-multipartform-data-example--post-form-data-with-file-and-data)\n* [Upload/Download progress](#user-content-uploaddownload-progress)\n* [Cancel HTTP request](#user-content-cancel-request)\n* [Android Media Scanner, and Download Manager Support](#user-content-android-media-scanner-and-download-manager-support)\n* [Self-Signed SSL Server](#user-content-self-signed-ssl-server)\n* [Transfer Encoding](#user-content-transfer-encoding)\n* [Drop-in Fetch Replacement](#user-content-drop-in-fetch-replacement)\n* [File System](#user-content-file-system)\n* [File access](#user-content-file-access)\n* [File stream](#user-content-file-stream)\n* [Manage cached files](#user-content-cache-file-management)\n* [Web API Polyfills](#user-content-web-api-polyfills)\n* [Performance Tips](#user-content-performance-tips)\n* [API References](https://github.com/RonRadtke/react-native-blob-util/wiki/Fetch-API)\n* [Caveats](#user-content-caveats)\n* [Development](#user-content-development)\n\n## About\n\nThis project was started in the cause of solving issue [facebook/react-native#854](https://github.com/facebook/react-native/issues/854), React Native's lacks of `Blob` implementation which results into problems when transferring binary data.\n\nIt is committed to making file access and transfer easier and more efficient for React Native developers. We've implemented highly customizable filesystem and network module which plays well together. For example, developers can upload and download data directly from/to storage, which is more efficient, especially for large files. The file system supports file stream, so you don't have to worry about OOM problem when accessing large files.\n\nIn `0.8.0` we introduced experimental Web API polyfills that make it possible to use browser-based libraries in React Native, such as, [FireBase JS SDK](https://github.com/joltup/rn-firebase-storage-upload-sample)\n\n## Installation\n\nInstall package from npm\n\n```sh\nnpm install --save react-native-blob-util\n```\n\nOr if using CocoaPods, add the pod to your `Podfile`\n\n```\npod 'react-native-blob-util',\n    :path =\u003e '../node_modules/react-native-blob-util'\n```\n\nAfter `0.10.3` you can install this package directly from Github\n\n```sh\n# replace \u003cbranch_name\u003e with any one of the branches\nnpm install --save github:RonRadtke/react-native-blob-util#\u003cbranch_name\u003e\n```\n\n**iOS**\n\nWhen using the package from npm, run `pod install` from the `ios` directory:\n\n```sh\ncd ios; pod install; cd ..\n```\n\n**Okhttp**\n\nFor using the library okhttp3 is required. It's in general included in react-native. The library uses the okhttp version shipped with react-native or used by your app. For very old devices android devices okhttp 3.12 can be used.\n\n**Manually Link Native Modules**\n\nIf you're using RN 0.60 or higher, manual linking should not be required anymore.\n\nIf automatically linking doesn't work for you, see instructions on [manually linking](https://github.com/RonRadtke/react-native-blob-util/wiki/Manually-Link-Package#index).\n\n**Automatically Link Native Modules**\n\nFor 0.29.2+ projects, simply link native packages via the following command (note: rnpm has been merged into react-native)\n\n```\nreact-native link react-native-blob-util\n```\n\nAs for projects \u003c 0.29 you need `rnpm` to link native packages\n\n```sh\nrnpm link\n```\n\nOptionally, use the following command to add Android permissions to `AndroidManifest.xml` automatically\n\n```sh\nRNFB_ANDROID_PERMISSIONS=true react-native react-native-blob-util\n```\n\npre 0.29 projects\n\n```sh\nRNFB_ANDROID_PERMISSIONS=true rnpm link\n```\n\nThe link script might not take effect if you have non-default project structure, please visit [the wiki](https://github.com/RonRadtke/react-native-blob-util/wiki/Manually-Link-Package) to link the package manually.\n\n**Grant Permission to External storage for Android 5.0 or lower**\n\nThe mechanism for granting Android permissions has slightly different since Android 6.0 released, please refer to [Official Document](https://developer.android.com/training/permissions/requesting.html).\n\nIf you're going to access external storage (say, SD card storage) for `Android 5.0` (or lower) devices, you might have to add the following line to `AndroidManifest.xml`.\n\n```diff\n\u003cmanifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    package=\"com.ReactNativeBlobUtiltest\"\n    android:versionCode=\"1\"\n    android:versionName=\"1.0\"\u003e\n\n    \u003cuses-permission android:name=\"android.permission.INTERNET\" /\u003e\n    \u003cuses-permission android:name=\"android.permission.SYSTEM_ALERT_WINDOW\"/\u003e\n+   \u003cuses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\" /\u003e\n+   \u003cuses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\" /\u003e\n+   \u003cuses-permission android:name=\"android.permission.DOWNLOAD_WITHOUT_NOTIFICATION\" /\u003e\n    ...\n\n```\n\nAlso, if you're going to use `Android Download Manager` you have to add this to `AndroidManifest.xml`\n\n```diff\n    \u003cintent-filter\u003e\n            \u003caction android:name=\"android.intent.action.MAIN\" /\u003e\n            \u003ccategory android:name=\"android.intent.category.LAUNCHER\" /\u003e\n+           \u003caction android:name=\"android.intent.action.DOWNLOAD_COMPLETE\"/\u003e\n    \u003c/intent-filter\u003e\n```\n\nIf you are going to use the `wifiOnly` flag, you need to add this to `AndroidManifest.xml`\n\n```diff\n+   \u003cuses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\" /\u003e\n    ...\n\n```\n\n**Grant Access Permission for Android 6.0**\n\nBeginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. So adding permissions in `AndroidManifest.xml` won't work for Android 6.0+ devices. To grant permissions in runtime, you might use [PermissionAndroid API](https://facebook.github.io/react-native/docs/permissionsandroid).\n\n## Usage\n\nES6\n\nThe module uses ES6 style export statement, simply use `import` to load the module.\n\n```js\nimport ReactNativeBlobUtil from 'react-native-blob-util'\n```\n\nES5\n\nIf you're using ES5 require statement to load the module, please add `default`. See [here](https://github.com/RonRadtke/react-native-blob-util/wiki/Trouble-Shooting#ReactNativeBlobUtilfetch-is-not-a-function) for more detail.\n\n```\nvar ReactNativeBlobUtil = require('react-native-blob-util').default\n```\n\n## HTTP Data Transfer\n\n### Regular Request\n\nAfter `0.8.0` react-native-blob-util automatically decides how to send the body by checking its type and `Content-Type` in the header. The rule is described in the following diagram\n\n\u003cimg src=\"img/RNFB-Flow-hd.png\" style=\"width : 90%\" /\u003e\n\nTo sum up:\n\n- To send a form data, the `Content-Type` header does not matter. When the body is an `Array` we will set proper content type for you.\n- To send binary data, you have two choices, use BASE64 encoded string or path points to a file contains the body.\n- If the `Content-Type` containing substring`;BASE64` or `application/octet` the given body will be considered as a BASE64 encoded data which will be decoded to binary data as the request body.\n- Otherwise, if a string starts with `ReactNativeBlobUtil-file://` (which can simply be done by `ReactNativeBlobUtil.wrap(PATH_TO_THE_FILE)`), it will try to find the data from the URI string after `ReactNativeBlobUtil-file://` and use it as the request body.\n- To send the body as-is, simply use a `Content-Type` header not containing `;BASE64` or `application/octet`.\n\n\u003e It is Worth to mentioning that the HTTP request uses cache by default, if you're going to disable it simply add a Cache-Control header `'Cache-Control' : 'no-store'`\n\n\u003e After 0.9.4, we disabled `Chunked` transfer encoding by default, if you're going to use it, you should explicitly set header `Transfer-Encoding` to `Chunked`.\n\n### Download example: Fetch files that need authorization token\n\nMost simple way is download to memory and stored as BASE64 encoded string, this is handy when the response data is small. Note that when it comes to authorization, not only can you use an authorization token, but this package will automatically pass the cookies created by normal js requests such as axios and fetch. Therefore, if you are using traditional cookie-based ways to authorize your user, you don't need to do anything before this package works.\n\n```js\n\n// send http request in a new thread (using native code)\nReactNativeBlobUtil.fetch('GET', 'http://www.example.com/images/img1.png', {\n    Authorization: 'Bearer access-token...',\n    // more headers  ..\n})\n        .then((res) =\u003e {\n            let status = res.info().status;\n\n            if (status == 200) {\n                // the conversion is done in native code\n                let base64Str = res.base64()\n                // the following conversions are done in js, it's SYNC\n                let text = res.text()\n                let json = res.json()\n            }\n            else {\n                // handle other status codes\n            }\n        })\n        // Something went wrong:\n        .catch((errorMessage, statusCode) =\u003e {\n            // error handling\n        })\n```\n\n### Download to storage directly\n\nIf the response data is large, that would be a bad idea to convert it into BASE64 string. A better solution is streaming the response directly into a file, simply add a `fileCache` option to config, and set it to `true`. This will make incoming response data stored in a temporary path **without** any file extension.\n\n**These files won't be removed automatically, please refer to [Cache File Management](#user-content-cache-file-management)**\n\n```js\nReactNativeBlobUtil\n        .config({\n            // add this option that makes response data to be stored as a file,\n            // this is much more performant.\n            fileCache: true,\n        })\n        .fetch('GET', 'http://www.example.com/file/example.zip', {\n            //some headers ..\n        })\n        .then((res) =\u003e {\n            // the temp file path\n            console.log('The file saved to ', res.path())\n        })\n```\n\n**Set Temp File Extension**\n\nSometimes you might need a file extension for some reason. For example, when using file path as the source of `Image` component, the path should end with something like .png or .jpg, you can do this by add `appendExt` option to `config`.\n\n```js\nReactNativeBlobUtil\n        .config({\n            fileCache: true,\n            // by adding this option, the temp files will have a file extension\n            appendExt: 'png'\n        })\n        .fetch('GET', 'http://www.example.com/file/example.zip', {\n            //some headers ..\n        })\n        .then((res) =\u003e {\n            // the temp file path with file extension `png`\n            console.log('The file saved to ', res.path())\n            // Beware that when using a file path as Image source on Android,\n            // you must prepend \"file://\"\" before the file path\n            imageView = \u003cImage source={{uri: Platform.OS === 'android' ? 'file://' + res.path() : '' + res.path()}}/\u003e\n        })\n```\n\n**Use Specific File Path**\n\nIf you prefer a particular file path rather than randomly generated one, you can use `path` option. We've added [several  constants](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#dirs) in v0.5.0 which represents commonly used directories.\n\n```js\nlet dirs = ReactNativeBlobUtil.fs.dirs\nReactNativeBlobUtil\n        .config({\n            // response data will be saved to this path if it has access right.\n            path: dirs.DocumentDir + '/path-to-file.anything'\n        })\n        .fetch('GET', 'http://www.example.com/file/example.zip', {\n            //some headers ..\n        })\n        .then((res) =\u003e {\n            // the path should be dirs.DocumentDir + 'path-to-file.anything'\n            console.log('The file saved to ', res.path())\n        })\n```\n\n**These files won't be removed automatically, please refer to [Cache File Management](#user-content-cache-file-management)**\n\n**Use File Transformer**\n\nIf you need to perform any processing on the bytes prior to it being written into storage (e.g. if you want it to be encrypted) then you can use `transform` option.  NOTE: you will need to set a transformer on the libray (see [Setting a File Transformer](#Setting-A-File-Transformer))\n\n```js\nReactNativeBlobUtil\n        .config({\n            // response data will be saved to this path if it has access right.\n            path: dirs.DocumentDir + '/path-to-file.anything',\n            transform: true\n        })\n        .fetch('GET', 'http://www.example.com/file/example.zip', {\n            //some headers ..\n        })\n        .then((res) =\u003e {\n            // the path should be dirs.DocumentDir + 'path-to-file.anything'\n            console.log('The file saved to ', res.path())\n        })\n```\n\n#### Upload example : Dropbox [files-upload](https://www.dropbox.com/developers/documentation/http/documentation#files-upload) API\n\n`react-native-blob-util` will convert the base64 string in `body` to binary format using native API, this process is done in a separated thread so that it won't block your GUI.\n\n```js\n\nReactNativeBlobUtil.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {\n    Authorization: \"Bearer access-token...\",\n    'Dropbox-API-Arg': JSON.stringify({\n        path: '/img-from-react-native.png',\n        mode: 'add',\n        autorename: true,\n        mute: false\n    }),\n    'Content-Type': 'application/octet-stream',\n    // here's the body you're going to send, should be a BASE64 encoded string\n    // (you can use \"base64\"(refer to the library 'mathiasbynens/base64') APIs to make one).\n    // The data will be converted to \"byte array\"(say, blob) before request sent.\n}, base64ImageString)\n        .then((res) =\u003e {\n            console.log(res.text())\n        })\n        .catch((err) =\u003e {\n            // error handling ..\n        })\n```\n\n### Upload a file from storage\n\nIf you're going to use a `file` as request body, just wrap the path with `wrap` API.\n\n```js\nReactNativeBlobUtil.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {\n    // dropbox upload headers\n    Authorization: \"Bearer access-token...\",\n    'Dropbox-API-Arg': JSON.stringify({\n        path: '/img-from-react-native.png',\n        mode: 'add',\n        autorename: true,\n        mute: false\n    }),\n    'Content-Type': 'application/octet-stream',\n    // Change BASE64 encoded data to a file path with prefix `ReactNativeBlobUtil-file://`.\n    // Or simply wrap the file path with ReactNativeBlobUtil.wrap().\n}, ReactNativeBlobUtil.wrap(PATH_TO_THE_FILE))\n        .then((res) =\u003e {\n            console.log(res.text())\n        })\n        .catch((err) =\u003e {\n            // error handling ..\n        })\n```\n\n### Multipart/form-data example: Post form data with file and data\n\nIn `version \u003e= 0.3.0` you can also post files with form data, just put an array in `body`, with elements have property `name`, `data`, and `filename`(optional).\n\nElements have property `filename` will be transformed into binary format, otherwise, it turns into utf8 string.\n\n```js\n\nReactNativeBlobUtil.fetch('POST', 'http://www.example.com/upload-form', {\n    Authorization: \"Bearer access-token\",\n    otherHeader: \"foo\",\n    'Content-Type': 'multipart/form-data',\n}, [\n    // element with property `filename` will be transformed into `file` in form data\n    {name: 'avatar', filename: 'avatar.png', data: binaryDataInBase64},\n    // custom content type\n    {name: 'avatar-png', filename: 'avatar-png.png', type: 'image/png', data: binaryDataInBase64},\n    // part file from storage\n    {name: 'avatar-foo', filename: 'avatar-foo.png', type: 'image/foo', data: ReactNativeBlobUtil.wrap(path_to_a_file)},\n    // elements without property `filename` will be sent as plain text\n    {name: 'name', data: 'user'},\n    {\n        name: 'info', data: JSON.stringify({\n            mail: 'example@example.com',\n            tel: '12345678'\n        })\n    },\n]).then((resp) =\u003e {\n    // ...\n}).catch((err) =\u003e {\n    // ...\n})\n```\n\nWhat if you want to append a file to form data? Just like [upload a file from storage](#user-content-upload-a-file-from-storage) example, wrap `data` by `wrap` API (this feature is only available for `version \u003e= v0.5.0`). On version \u003e= `0.6.2`, it is possible to set custom MIME type when appending a file to form data. But keep in mind when the file is large it's likely to crash your app. Please consider use other strategy (see [#94](https://github.com/joltup/react-native-blob-util/issues/94)).\n\n```js\n\nReactNativeBlobUtil.fetch('POST', 'http://www.example.com/upload-form', {\n    Authorization: \"Bearer access-token\",\n    otherHeader: \"foo\",\n    // this is required, otherwise it won't be process as a multipart/form-data request\n    'Content-Type': 'multipart/form-data',\n}, [\n    // append field data from file path\n    {\n        name: 'avatar',\n        filename: 'avatar.png',\n        // Change BASE64 encoded data to a file path with prefix `ReactNativeBlobUtil-file://`.\n        // Or simply wrap the file path with ReactNativeBlobUtil.wrap().\n        data: ReactNativeBlobUtil.wrap(PATH_TO_THE_FILE)\n    },\n    {\n        name: 'ringtone',\n        filename: 'ring.mp3',\n        // use custom MIME type\n        type: 'application/mp3',\n        // upload a file from asset is also possible in version \u003e= 0.6.2\n        data: ReactNativeBlobUtil.wrap(ReactNativeBlobUtil.fs.asset('default-ringtone.mp3'))\n    },\n    // elements without property `filename` will be sent as plain text\n    {name: 'name', data: 'user'},\n    {\n        name: 'info', data: JSON.stringify({\n            mail: 'example@example.com',\n            tel: '12345678'\n        })\n    },\n]).then((resp) =\u003e {\n    // ...\n}).catch((err) =\u003e {\n    // ...\n})\n```\n\n### Upload/Download progress\n\nIn `version \u003e= 0.4.2` it is possible to know the upload/download progress. After `0.7.0` IOS and Android upload progress are also supported.\n\n```js\n  ReactNativeBlobUtil.fetch('POST', 'http://www.example.com/upload', {\n    //... some headers,\n    'Content-Type': 'octet-stream'\n}, base64DataString)\n        // listen to upload progress event\n        .uploadProgress((written, total) =\u003e {\n            console.log('uploaded', written / total)\n        })\n        // listen to download progress event\n        .progress((received, total) =\u003e {\n            console.log('progress', received / total)\n        })\n        .then((resp) =\u003e {\n            // ...\n        })\n        .catch((err) =\u003e {\n            // ...\n        })\n```\n\nIn `0.9.6`, you can specify an object as the first argument which contains `count` and `interval`, to the frequency of progress event (this will be done in the native context a reduce RCT bridge overhead). Notice that `count` argument will not work if the server does not provide response content length.\n\n```js\n  ReactNativeBlobUtil.fetch('POST', 'http://www.example.com/upload', {\n    //... some headers,\n    'Content-Type': 'octet-stream'\n}, base64DataString)\n        // listen to upload progress event, emit every 250ms\n        .uploadProgress({interval: 250}, (written, total) =\u003e {\n            console.log('uploaded', written / total)\n        })\n        // listen to download progress event, every 10%\n        .progress({count: 10}, (received, total) =\u003e {\n            console.log('progress', received / total)\n        })\n        .then((resp) =\u003e {\n            // ...\n        })\n        .catch((err) =\u003e {\n            // ...\n        })\n```\n\n### Cancel Request\n\nAfter `0.7.0` it is possible to cancel an HTTP request. Upon cancellation, it throws a promise rejection, be sure to catch it.\n\n```js\nlet task = ReactNativeBlobUtil.fetch('GET', 'http://example.com/file/1')\n\ntask.then(() =\u003e { ...\n})\n        // handle request cancelled rejection\n        .catch((err) =\u003e {\n            console.log(err)\n        })\n// cancel the request, the callback function is optional\ntask.cancel((err) =\u003e { ...\n})\n\n```\n\n### Drop-in Fetch Replacement\n\n0.9.0\n\nIf you have existing code that uses `whatwg-fetch`(the official **fetch**), it's not necessary to replace them with `ReactNativeBlobUtil.fetch`, you can simply use our **Fetch Replacement**. The difference between Official them is official fetch uses [whatwg-fetch](https://github.com/github/fetch) which wraps XMLHttpRequest polyfill under the hood. It's a great library for web developers, but does not play very well with RN. Our implementation is simply a wrapper of our `fetch` and `fs` APIs, so you can access all the features we provided.\n\n[See document and examples](https://github.com/RonRadtke/react-native-blob-util/wiki/Fetch-API#fetch-replacement)\n\n### Android Media Scanner, and Download Manager Support\n\nIf you want to make a file in `External Storage` becomes visible in Picture, Downloads, or other built-in apps, you will have to use `Media Scanner` or `Download Manager` or the `Media Storage`.\n\n**Media Scanner**\n\nMedia scanner scans the file and categorizes by given MIME type, if MIME type not specified, it will try to resolve the file using its file extension.\n\n```js\n\nReactNativeBlobUtil\n        .config({\n            // DCIMDir is in external storage\n            path: dirs.DCIMDir + '/music.mp3'\n        })\n        .fetch('GET', 'http://example.com/music.mp3')\n        .then((res) =\u003e ReactNativeBlobUtil.fs.scanFile([{path: res.path(), mime: 'audio/mpeg'}]))\n        .then(() =\u003e {\n            // scan file success\n        })\n        .catch((err) =\u003e {\n            // scan file error\n        })\n```\n\n**Download Manager**\n\nWhen downloading large files on Android it is recommended to use `Download Manager`, it supports a lot of native features like the progress bar, and notification, also the download task will be handled by OS, and more efficient.\n\n\u003cimg src=\"img/download-manager.png\" width=\"256\"\u003e\n\nWhen using DownloadManager, `fileCache` and `path` properties in `config` will not take effect, because Android DownloadManager can only store files to external storage, also notice that Download Manager can only support `GET` method, which means the request body will be ignored.\n\nWhen download complete, DownloadManager will generate a file path so that you can deal with it.\n\n```js\nReactNativeBlobUtil\n        .config({\n            addAndroidDownloads: {\n                useDownloadManager: true, // \u003c-- this is the only thing required\n                // Optional, override notification setting (default to true)\n                notification: false,\n                // Optional, but recommended since android DownloadManager will fail when\n                // the url does not contains a file extension, by default the mime type will be text/plain\n                mime: 'text/plain',\n                description: 'File downloaded by download manager.'\n            }\n        })\n        .fetch('GET', 'http://example.com/file/somefile')\n        .then((resp) =\u003e {\n            // the path of downloaded file\n            resp.path()\n        })\n```\n\nYour app might not have right to remove/change the file created by Download Manager, therefore you might need to [set custom location to the download task](https://github.com/wkh237/react-native-fetch-blob/issues/236).\n\n**Download Notification and Visibility in Download App (Android Only)**\n\n\u003cimg src=\"img/android-notification1.png\" width=\"256\"\u003e\n\u003cimg src=\"img/android-notification2.png\" width=\"256\"\u003e\n\n\nIf you need to display a notification upon the file is downloaded to storage (as the above) or make the downloaded file visible in \"Downloads\" app. You have to add some options to `config`.\n\n```js\nReactNativeBlobUtil.config({\n    fileCache: true,\n    // android only options, these options be a no-op on IOS\n    addAndroidDownloads: {\n        // Show notification when response data transmitted\n        notification: true,\n        // Title of download notification\n        title: 'Great ! Download Success ! :O ',\n        // File description (not notification description)\n        description: 'An image file.',\n        mime: 'image/png',\n        // Make the file scannable  by media scanner\n        mediaScannable: true,\n    }\n})\n        .fetch('GET', 'http://example.com/image1.png')\n        .then(...)\n```\n\n**Open Downloaded File with Intent**\n\nThis is a new feature added in `0.9.0` if you're going to open a file path using official [Linking](https://facebook.github.io/react-native/docs/linking.html) API that might not work as expected, also, if you're going to install an APK in `Downloads` app, that will not function too. As an alternative, you can try `actionViewIntent` API, which will send an ACTION_VIEW intent for you which uses the given `MIME` type.\n\nDownload and install an APK programmatically\n\nNote:\nbe sure to specify the path, do not use the default path, because the permission problem causes the installation to fail, parsing the package fails\n\ndefault path: `/data/data/com.android.providers.downloads/cache/xxx.apk`   // Will cause parsing of the package to fail，Unable to install APK\n\n```js\n\nconst android = ReactNativeBlobUtil.android\nconst dirs = ReactNativeBlobUtil.fs.dirs;\nconst apkUrl = \"http://www.example.com/awesome.apk\";    \nconst fileName = url.substring(url.lastIndexOf('/') + 1);\n\nReactNativeBlobUtil.config({\n    addAndroidDownloads: {\n        useDownloadManager: true,\n        path: `${dirs.DownloadDir}/${fileName}`,    // \u003c-- Must specify\n        title: 'awesome.apk',\n        description: 'An APK that will be installed',\n        mime: 'application/vnd.android.package-archive',\n        mediaScannable: true,\n        notification: true,\n    }\n})\n        .fetch('GET', `http://www.example.com/awesome.apk`)\n        .then((res) =\u003e {\n            android.actionViewIntent(res.path(), 'application/vnd.android.package-archive')\n        })\n```\n\nOr show an image in image viewer\n\n```js\n      android.actionViewIntent(PATH_OF_IMG, 'image/png')\n```\n\n## File System\n\n### Android Media Storage\n\nAndroid 10 introduced scoped storage and thus new APIs to store files to Documents, Downloads, Music and other collections. Version 0.14.0 introduced an API to access files in the Media Store but also to create and write to new files in the Media Store. In general you only can access files in the Media Store created by your app, or selected by a picker.\n\n#### CopyToMediaStore\n\nCopies an existing file from the internal Storage to the Media Store. \u003cbr\u003e An example for downloading a file and storing it to the `downloads` collection\n\n```js\nReactNativeBlobUtil\n        .config({\n            fileCache: true\n        })\n        .fetch('GET', 'https://example.de/image.png')\n        .then(async (res) =\u003e {\n            let result = await ReactNativeBlobUtil.MediaCollection.copyToMediaStore({\n                        name: filename, // name of the file\n                        parentFolder: '', // subdirectory in the Media Store, e.g. HawkIntech/Files to create a folder HawkIntech with a subfolder Files and save the image within this folder\n                        mimeType: 'image/png' // MIME type of the file\n                    },\n                    'Download', // Media Collection to store the file in (\"Audio\" | \"Image\" | \"Video\" | \"Download\")\n                    res.path() // Path to the file being copied in the apps own storage\n            );\n        });\n```\n\nThis example is taking advantage of the fileCache option to directly store the downloaded file and get a path for. \u003cbr\u003e\nCurrently it's not possible to write data directly from a string recevied by fetch, but only to copy it from a file.\n\n#### createMediaFile\n\nCreates a new file in the specified collection without writing any data\n\n````js\nlet path = await ReactNativeBlobUtil.MediaCollection.createMediafile({\n            name: filename, // name of the file\n            parentFolder: '', // subdirectory in the Media Store, e.g. HawkIntech/Files to create a folder HawkIntech with a subfolder Files and save the image within this folder\n            mimeType: 'image/png' // MIME type of the file\n        }, 'Download'// Media Collection to store the file in (\"Audio\" | \"Image\" | \"Video\" | \"Download\")\n);\n````\n\n#### writeMediaFile\n\nWrites data from a file in the apps storage to an existing entry of the Media Store\n````js\nawait ReactNativeBlobUtil.MediaCollection.writeToMediafile('content://....', // content uri of the entry in the media storage\n        localpath // path to the file that should be copied\n);\n````\n\nCopies and tranforms data from a file in the apps storage to an existing entry of the Media Store. NOTE: you must set a transformer on the file in order for the transformation to happen (see [Setting a File Transformer](#Setting-A-File-Transformer)).\n\n````js\nawait ReactNativeBlobUtil.MediaCollection.writeToMediafileWithTransform('content://....', // content uri of the entry in the media storage\n        localpath // path to the file that should be copied\n);\n````\n\n#### copyToInternal\nCopies an entry form the media storage to the apps internal storage.\n````js\nlet destpath = ReactNativeBlobUtil.dirs.CacheDir + '/image.png';\nawait ReactNativeBlobUtil.MediaCollection.copyToInternal('content://....', // content uri of the entry in the media storage\n        destpath // path to destination the entry should be copied to\n);\n````\n\n### File Access\n\nFile access APIs were made when developing `v0.5.0`, which helping us write tests, and was not planned to be a part of this module. However, we realized that it's hard to find a great solution to manage cached files, everyone who uses this module may need these APIs for their cases.\n\nBefore start using file APIs, we recommend read [Differences between File Source](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#differences-between-file-source) first.\n\nFile Access APIs\n\n- [asset (0.6.2)](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#assetfilenamestringstring)\n- [dirs](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#dirs)\n- [createFile](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#createfilepath-data-encodingpromise)\n- [writeFile (0.6.0)](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#writefilepathstring-contentstring--array-encodingstring-appendbooleanpromise)\n- writeFileWithTransform\n- [appendFile (0.6.0) ](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#appendfilepathstring-contentstring--arraynumber-encodingstring-promisenumber)\n- [readFile (0.6.0)](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#readfilepath-encodingpromise)\n- readFileWithTransform\n- [readStream](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#readstreampath-encoding-buffersize-interval-promisernfbreadstream)\n- [hash (0.10.9)](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#hashpath-algorithm-promise)\n- [writeStream](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#writestreampathstring-encodingstringpromise)\n- [hash](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#hashpath-algorithmpromise)\n- [unlink](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#unlinkpathstringpromise)\n- [mkdir](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#mkdirpathstringpromise)\n- [ls](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#lspathstringpromise)\n- [mv](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#mvfromstring-tostringpromise)\n- [cp](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#cpsrcstring-deststringpromise)\n- [exists](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#existspathstringpromise)\n- [isDir](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#isdirpathstringpromise)\n- [stat](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#statpathstringpromise)\n- [lstat](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#lstatpathstringpromise)\n- [scanFile (Android only)](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API#scanfilepathstringpromise-androi-only)\n\nSee [File API](https://github.com/RonRadtke/react-native-blob-util/wiki/File-System-Access-API) for more information\n\n### File Stream\n\nIn `v0.5.0` we've added  `writeStream` and `readStream`, which allows your app read/write data from the file path. This API creates a file stream, rather than convert entire data into BASE64 encoded string. It's handy when processing **large files**.\n\nWhen calling `readStream` method, you have to `open` the stream, and start to read data. When the file is large, consider using an appropriate `bufferSize` and `interval` to reduce the native event dispatching overhead (see [Performance Tips](#user-content-performance-tips))\n\n\u003e The file stream event has a default throttle(10ms) and buffer size which preventing it cause too much overhead to main thread, you can also [tweak these values](#user-content-performance-tips).\n\n```js\nlet data = ''\nReactNativeBlobUtil.fs.readStream(\n        // file path\n        PATH_TO_THE_FILE,\n        // encoding, should be one of `base64`, `utf8`, `ascii`\n        'base64',\n        // (optional) buffer size, default to 4096 (4095 for BASE64 encoded data)\n        // when reading file in BASE64 encoding, buffer size must be multiples of 3.\n        4095)\n        .then((ifstream) =\u003e {\n            ifstream.open()\n            ifstream.onData((chunk) =\u003e {\n                // when encoding is `ascii`, chunk will be an array contains numbers\n                // otherwise it will be a string\n                data += chunk\n            })\n            ifstream.onError((err) =\u003e {\n                console.log('oops', err)\n            })\n            ifstream.onEnd(() =\u003e {\n                \u003cImage source={{uri: 'data:image/png,base64' + data}}\n    })\n            })\n```\n\nWhen using `writeStream`, the stream object becomes writable, and you can then perform operations like `write` and `close`.\n\nSince version 0.10.9 `write()` resolves with the `ReactNativeBlobUtil` instance so you can promise-chain write calls:\n\n```js\nReactNativeBlobUtil.fs.writeStream(\n        PATH_TO_FILE,\n        // encoding, should be one of `base64`, `utf8`, `ascii`\n        'utf8',\n        // should data append to existing content ?\n        true\n)\n        .then(ofstream =\u003e ofstream.write('foo'))\n        .then(ofstream =\u003e ofstream.write('bar'))\n        .then(ofstream =\u003e ofstream.write('foobar'))\n        .then(ofstream =\u003e ofstream.close())\n        .catch(console.error)\n```\n\nor\n\n```js\nReactNativeBlobUtil.fs.writeStream(\n        PATH_TO_FILE,\n        // encoding, should be one of `base64`, `utf8`, `ascii`\n        'utf8',\n        // should data append to existing content ?\n        true\n)\n        .then(stream =\u003e Promise.all([\n            stream.write('foo'),\n            stream.write('bar'),\n            stream.write('foobar')\n        ]))\n        // Use array destructuring to get the stream object from the first item of the array we get from Promise.all()\n        .then(([stream]) =\u003e stream.close())\n        .catch(console.error)\n```\n\nYou should **NOT** do something like this:\n\n```js\nReactNativeBlobUtil.fs.writeStream(\n        PATH_TO_FILE,\n        // encoding, should be one of `base64`, `utf8`, `ascii`\n        'utf8',\n        // should data append to existing content ?\n        true)\n        .then((ofstream) =\u003e {\n            // BAD IDEA - Don't do this, those writes are unchecked:\n            ofstream.write('foo')\n            ofstream.write('bar')\n            ofstream.close()\n        })\n        .catch(console.error)  // Cannot catch any write() errors!\n```\n\nThe problem with the above code is that the promises from the `ofstream.write()` calls are detached and \"Lost\". That means the entire promise chain A) resolves without waiting for the writes to finish and B) any errors caused by them are lost. That code may _seem_ to work if there are no errors, but those writes are of the type \"fire and forget\": You start them and then turn away and never know if they really succeeded.\n\n### Cache File Management\n\nWhen using `fileCache` or `path` options along with `fetch` API, response data will automatically store into the file system. The files will **NOT** removed unless you `unlink` it. There're several ways to remove the files\n\n```js\n\n// remove file using ReactNativeBlobUtilResponse.flush() object method\nReactNativeBlobUtil.config({\n    fileCache: true\n})\n        .fetch('GET', 'http://example.com/download/file')\n        .then((res) =\u003e {\n            // remove cached file from storage\n            res.flush()\n        })\n\n// remove file by specifying a path\nReactNativeBlobUtil.fs.unlink('some-file-path').then(() =\u003e {\n    // ...\n})\n\n```\n\nYou can also group requests by using `session` API and use `dispose` to remove them all when needed.\n\n```js\n\nReactNativeBlobUtil.config({\n    fileCache: true\n})\n        .fetch('GET', 'http://example.com/download/file')\n        .then((res) =\u003e {\n            // set session of a response\n            res.session('foo')\n        })\n\nReactNativeBlobUtil.config({\n    // you can also set session beforehand\n    session: 'foo'\n    fileCache: true\n})\n        .fetch('GET', 'http://example.com/download/file')\n        .then((res) =\u003e {\n            // ...\n        })\n\n// or put an existing file path to the session\nReactNativeBlobUtil.session('foo').add('some-file-path')\n// remove a file path from the session\nReactNativeBlobUtil.session('foo').remove('some-file-path')\n// list paths of a session\nReactNativeBlobUtil.session('foo').list()\n// remove all files in a session\nReactNativeBlobUtil.session('foo').dispose().then(() =\u003e { ...\n})\n\n```\n\n### Transfer Encoding\n\nAfter `0.9.4`, the `Chunked` transfer encoding is disabled by default due to some service provider may not support chunked transfer. To enable it, set `Transfer-Encoding` header to `Chunked`.\n\n```js\nReactNativeBlobUtil.fetch('POST', 'http://example.com/upload', {'Transfer-Encoding': 'Chunked'}, bodyData)\n```\n\n### Self-Signed SSL Server\n\nBy default, react-native-blob-util does NOT allow connection to unknown certification provider since it's dangerous. To connect a server with self-signed certification, you need to add `trusty` to `config` explicitly. This function is available for version \u003e= `0.5.3`\nIn addition since ``0.16.0`` you'll have to define your own trust manager for android.\n````java\n....\nimport com.ReactNativeBlobUtil.ReactNativeBlobUtilUtils;\n...\n\npublic class MainApplication extends Application implements ReactApplication {\n    ...\n    @Override\n    public void onCreate() {\n       ...\n        ReactNativeBlobUtilUtils.sharedTrustManager = x509TrustManager = new X509TrustManager() {\n                @Override\n                public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {\n                }\n\n                @Override\n                public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {\n                }\n\n                @Override\n                public java.security.cert.X509Certificate[] getAcceptedIssuers() {\n                    return new java.security.cert.X509Certificate[]{};\n                }\n        };\n        ...\n    }\n````\n\n#### Kotlin\n````kotlin\n....\nimport com.ReactNativeBlobUtil.ReactNativeBlobUtilUtils;\nimport javax.net.ssl.X509TrustManager\n...\n\npublic class MainApplication extends Application implements ReactApplication {\n    ...\n    public void onCreate() {\n       ...\n        ReactNativeBlobUtilUtils.sharedTrustManager = object : X509TrustManager {\n          override fun checkClientTrusted(chain: Array\u003cjava.security.cert.X509Certificate\u003e, authType: String) {}\n\n          override fun checkServerTrusted(chain: Array\u003cjava.security.cert.X509Certificate\u003e, authType: String) {}\n\n          override fun getAcceptedIssuers(): Array\u003cjava.security.cert.X509Certificate\u003e {\n            return arrayOf()\n          }\n        };\n        ...\n    }\n````\n\n```js\nReactNativeBlobUtil.config({\n    trusty: true\n})\n        .fetch('GET', 'https://mysite.com')\n        .then((resp) =\u003e {\n            // ...\n        })\n```\n\n### WiFi only requests\n\nIf you wish to only route requests through the Wifi interface, set the below configuration. Note: On Android, the `ACCESS_NETWORK_STATE` permission must be set, and this flag will only work on API version 21 (Lollipop, Android 5.0) or above. APIs below 21 will ignore this flag.\n\n```js\nReactNativeBlobUtil.config({\n    wifiOnly: true\n})\n        .fetch('GET', 'https://mysite.com')\n        .then((resp) =\u003e {\n            // ...\n        })\n```\n\n### Transform Files\n\nSometimes you may need the files to be transformed after reading from storage or before writing into storage (eg encryption/decyrption). In order to perform the transformations, use `readFileWithTransform` and `writeFileWithTransform`. NOTE: you must set a transformer on the file in order for the transformation to happen (see [Setting a File Transformer](#Setting-A-File-Transformer)).\n\n## Web API Polyfills\n\nAfter `0.8.0` we've made some [Web API polyfills](https://github.com/RonRadtke/react-native-blob-util/wiki/Web-API-Polyfills-(experimental)) that makes some browser-based library available in RN.\n\n- Blob\n- XMLHttpRequest (Use our implementation if you're going to use it with Blob)\n\n\n## Setting A File Transformer\n\nSetting a file transformer will allow you to specify how data should be transformed whenever the library is writing into storage or reading from storage. A use case for this is if you want the files handled by this library to be encrypted.\n\nIf you want to use a file transformer, you must implement an interface defined in:\n\n[ReactNativeBlobUtilFileTransformer.h (iOS)](/ios/ReactNativeBlobUtilFileTransformer.h)\n\n[ReactNativeBlobUtilFileTransformer.java (Android)](/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFileTransformer.java)\n\nThen you set the File Transformer during app startup\n\nAndroid:\n```java\npublic class MainApplication extends Application implements ReactApplication {\n    ...\n    @Override\n    public void onCreate() {\n       ...\n       ReactNativeBlobUtilFileTransformer.sharedFileTransformer = new MyCustomEncryptor();\n       ...\n    }\n```\n\niOS:\n```m\n@implementation AppDelegate\n...\n- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions\n{\n    ...\n    [ReactNativeBlobUtilFileTransformer setFileTransformer: MyCustomEncryptor.new];\n    ...\n}\n```\n\nHere are the places where the transformer would apply\n- Reading a file from the file system\n- Writing a file into the file system\n- Http response is downloaded to storage directly\n\n## Performance Tips\n\n**Read Stream and Progress Event Overhead**\n\nIf the process seems to block JS thread when file is large when reading data via `fs.readStream`. It might because the default buffer size is quite small (4kb) which result in a lot of events triggered from JS thread. Try to increase the buffer size (for example 100kb = 102400) and set a larger interval (available for 0.9.4+, the default value is 10ms) to limit the frequency.\n\n**Reduce RCT Bridge and BASE64 Overhead**\n\nReact Native connects JS and Native context by passing JSON around React Native bridge, and there will be an overhead to convert data before they sent to each side. When data is large, this will be quite a performance impact to your app. It's recommended to use file storage instead of BASE64 if possible.The following chart shows how much faster when loading data from storage than BASE64 encoded string on iPhone 6.\n\n\u003cimg src=\"img/performance_1.png\" style=\"width : 100%\"/\u003e\n\n**ASCII Encoding has /terrible Performance**\n\nDue to the [lack of typed array implementation in JavascriptCore, and limitation of React Native structure](https://github.com/facebook/react-native/issues/1424), to convert data to JS byte array spends lot of time. Use it only when needed, the following chart shows how much time it takes when reading a file with different encoding.\n\n\u003cimg src=\"img/performance_encoding.png\" style=\"width : 100%\"/\u003e\n\n**Concat and Replacing Files**\n\nIf you're going to concatenate files, you don't have to read the data to JS context anymore! In `0.8.0` we introduced new encoding `uri` for writeFile and appendFile API, which make it possible to handle the whole process in native.\n\n\u003cimg src=\"img/performance_f2f.png\" style=\"width : 100%\"/\u003e\n\n## Caveats\n\n* This library does not urlencode unicode characters in URL automatically, see [#146](https://github.com/wkh237/react-native-fetch-blob/issues/146).\n* When you create a `Blob` , from an existing file, the file **WILL BE REMOVED** if you `close` the blob.\n* If you replaced `window.XMLHttpRequest` for some reason (e.g. make Firebase SDK work), it will also affect how official `fetch` works (basically it should work just fine).\n* When file stream and upload/download progress event slow down your app, consider an upgrade to `0.9.6+`, use [additional arguments](https://github.com/RonRadtke/react-native-blob-util/wiki/Fetch-API#fetchprogressconfig-eventlistenerpromiseReactNativeBlobUtilresponse) to limit its frequency.\n* When passing a file path to the library, remove `file://` prefix.\n\nwhen you got a problem, have a look at [Trouble Shooting](https://github.com/RonRadtke/react-native-blob-util/wiki/Trouble-Shooting).\n\n## Changes\n\nSee [release notes](https://github.com/RonRadtke/react-native-blob-util/releases)\n\n### Development\n\nIf you're interested in hacking this module, check our [development guide](https://github.com/RonRadtke/react-native-blob-util/wiki/Home), there might be some helpful information. Please feel free to make a PR or file an issue.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRonRadtke%2Freact-native-blob-util","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRonRadtke%2Freact-native-blob-util","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRonRadtke%2Freact-native-blob-util/lists"}