{"id":19682168,"url":"https://github.com/flyskywhy/react-native-get-asset","last_synced_at":"2026-05-11T07:19:33.386Z","repository":{"id":200553489,"uuid":"705940894","full_name":"flyskywhy/react-native-get-asset","owner":"flyskywhy","description":"Copy asset to file system, or read asset as base64 data url","archived":false,"fork":false,"pushed_at":"2023-10-17T02:40:57.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-10T10:55:02.366Z","etag":null,"topics":["android","asset","base64","copy","data-url","dataurl","download","expo-asset","ios","react-native","react-native-fs","storage","web"],"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/flyskywhy.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-10-17T02:07:50.000Z","updated_at":"2023-10-17T04:17:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"cf523c6d-6944-4c6d-866b-87ef301fda5a","html_url":"https://github.com/flyskywhy/react-native-get-asset","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"217dba7d9d1af7bd033bc4a47945fde1ee5a21d4"},"previous_names":["flyskywhy/react-native-get-asset"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/flyskywhy/react-native-get-asset","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flyskywhy%2Freact-native-get-asset","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flyskywhy%2Freact-native-get-asset/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flyskywhy%2Freact-native-get-asset/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flyskywhy%2Freact-native-get-asset/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flyskywhy","download_url":"https://codeload.github.com/flyskywhy/react-native-get-asset/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flyskywhy%2Freact-native-get-asset/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274578521,"owners_count":25310958,"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-11T02:00:13.660Z","response_time":74,"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":["android","asset","base64","copy","data-url","dataurl","download","expo-asset","ios","react-native","react-native-fs","storage","web"],"created_at":"2024-11-11T18:09:50.246Z","updated_at":"2026-05-11T07:19:28.331Z","avatar_url":"https://github.com/flyskywhy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-get-asset\n\n[![npm version](http://img.shields.io/npm/v/react-native-get-asset.svg?style=flat-square)](https://npmjs.org/package/react-native-get-asset \"View this project on npm\")\n[![npm downloads](http://img.shields.io/npm/dm/react-native-get-asset.svg?style=flat-square)](https://npmjs.org/package/react-native-get-asset \"View this project on npm\")\n[![npm licence](http://img.shields.io/npm/l/react-native-get-asset.svg?style=flat-square)](https://npmjs.org/package/react-native-get-asset \"View this project on npm\")\n[![Platform](https://img.shields.io/badge/platform-ios%20%7C%20android%20%7C%20web-989898.svg?style=flat-square)](https://npmjs.org/package/react-native-get-asset \"View this project on npm\")\n\nDescribed how to bundle asset automatically at bundle time, and one function to copy asset to file system or read asset as base64 data url on Android, iOS and Web at debug or release run time.\n\n## Install\n\n    npm install react-native-get-asset\n\nNote: `peerDependencies` are `expo-asset` and `react-native-fs`.\n\n## Bundle asset\n\nUse `environment.dds` as an example, it's very simple to bundle `environment.dds` file into APP as an asset automatically at bundle time:\n\n* add `'dds'` in `metro.config.js` e.g. \u003chttps://github.com/flyskywhy/GCanvasRNExamples/blob/master/metro.config.js\u003e\n* move file as `APP/public/textures/environment.dds`\n* `require('../public/textures/environment.dds')` in `APP/src/SomeComponent.js`\n\n## `src` below support Android, iOS and Web\n\nCause `appHtml: resolveApp('public/index.html')` in `node_modules/react-scripts/config/paths.js` which works with [react-native-web](https://github.com/necolas/react-native-web) and [react-app-rewired](https://github.com/timarney/react-app-rewired), so it's better to put assets files into `APP/public/` thus Web can use them too, that's why e.g. `src: Platform.OS !== 'web' ? require('../public/textures/environment.dds') : 'textures/environment.dds'` below.\n\nPS: The usage of `react-app-rewired` can ref to [my blog](https://github.com/flyskywhy/g/blob/master/i%E4%B8%BB%E8%A7%82%E7%9A%84%E4%BD%93%E9%AA%8C%E6%96%B9%E5%BC%8F/t%E5%BF%AB%E4%B9%90%E7%9A%84%E4%BD%93%E9%AA%8C/%E7%94%B5%E4%BF%A1/Tool/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/JavaScript/React%E4%BD%BF%E7%94%A8%E8%AF%A6%E8%A7%A3.md#rn--060-%E7%9A%84%E5%AE%89%E8%A3%85-react-native-web).\n\n## `downloadUrlOrRequireId2Storage()` to copy asset to file system\n\ne.g. you can modify\n```\nconst MODEL_URL =\n  'https://github.com/facebookresearch/playtorch/releases/download/v0.2.0/yolov5s.ptl';\n...\n    const filePath = await MobileModel.download(MODEL_URL);\n\n```\ninto\n```\nimport GetAsset from 'react-native-get-asset';\n...\nconst MODEL_URL =\n  Platform.OS !== 'web'\n    ? require('../../public/pytorch/yolov5s.ptl')\n    : 'pytorch/yolov5s.ptl';\n...\n      const filePath = await GetAsset.downloadUrlOrRequireId2Storage({\n        src: MODEL_URL,\n        dst:\n          Platform.OS !== 'web' \u0026\u0026\n          Platform.select({\n            android: `${RNFS.ExternalDirectoryPath}/detectObjects.ptl`,\n            ios: `${RNFS.DocumentDirectoryPath}/detectObjects.ptl`,\n          }),\n        iosReleaseRequireIdAvoidCopy: true, // default is false\n      });\n```\nUnlike asset on Android zipped in release.apk so must unzip copy, asset on iOS release is in bundle folder so that can avoid copy to access it directly, so can `iosReleaseRequireIdAvoidCopy: true` here.\n\nPS: If `react-native-get-asset` does not satisfy your APP situation, you can try [react-native-filereader](https://github.com/flyskywhy/react-native-filereader) or [react-native-blob-util](https://github.com/RonRadtke/react-native-blob-util).\n\n## `downloadUrlOrRequireId2DataURL()` to read asset as base64 data url\n\ne.g. \u003chttps://github.com/flyskywhy/GCanvasRNExamples/blob/master/src/nonDeclarative.js\u003e:\n```\nimport GetAsset from 'react-native-get-asset';\n...\n  const url = await GetAsset.downloadUrlOrRequireId2DataURL({\n    // src: 'https://raw.githubusercontent.com/brianzinn/react-babylonjs/v3.1.3/packages/storybook/storyboard-site/assets/textures/environment.dds';\n    src: Platform.OS !== 'web' ? require('../public/textures/environment.dds') : 'textures/environment.dds',\n    urlAvoidDataURL: true, // default is false\n  });\n```\nIf your other code can deal with http url, you can `urlAvoidDataURL: true` here to return url instead of data url.\n\nPS: [data-uri.macro](https://github.com/Andarist/data-uri.macro) can convert files to data-uris at bundle time to avoid these asset matter.\n\n## Donate\nTo support my work, please consider donate.\n\n- ETH: 0xd02fa2738dcbba988904b5a9ef123f7a957dbb3e\n\n- \u003cimg src=\"https://raw.githubusercontent.com/flyskywhy/flyskywhy/main/assets/alipay_weixin.png\" width=\"500\"\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflyskywhy%2Freact-native-get-asset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflyskywhy%2Freact-native-get-asset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflyskywhy%2Freact-native-get-asset/lists"}