react-natvie-fetch-blob使用
2019獨角獸企業重金招聘Python工程師標準>>>
react-natvie-fetch-blob
網上搜索了許多關于react-natvie-fetch-blob 的使用介紹,發現中文文檔很少。實在沒辦法就直接去看github上門的文檔了,做了一些筆記。
英語不怎好,如果寫的有何錯誤之處敬請諒解、指導
https://github.com/aroth/react-native-uploader
我選擇react-natvie-fetch-blob的原因
這里表述的是個人觀點,不具備專業性和嚴謹性
- React Native 上傳下載的第三發也有挺多的,比如react-native-fileupload。對于簡單的上傳下載也很好用,但是功能上還是有一些局限性,比如上傳進度
- react-natvie-fetch-blob 功能很強大,支持進度,還有很多很細心的功能
- react-natvie-fetch-blob 性能也很好,基本能勝任數據傳輸的所有功能
特性
- 傳輸數據直接存取,而不需要base64做跨接
- 文件接口支持一般文件,Asset 文件,相機膠卷文件
- Native-to-native 文件操作接口,減少了JS橋接而導致的性能損耗
- 文件流支持處理大文件
- Blob, File, XMLHttpRequest polyfills that make browser-based library available in RN (experimental)
- 支持JSON 流(Oboe.js)
相關
這個項目的起始出發點是為了解決這個問題 facebook/react-native#854
還是看原文吧:
This project was started in the cause of solving issue facebook/react-native#854, React Native's lacks of Blob implementation which results into problems when transferring binary data.
It 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.
In 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`
安裝
安裝包,安裝完您也可以直接跳到第5步按照wiki教材配置ios和Android環境
npm install --save react-native-fetch-blob或者如果你使用CocoaPods 把下面的加入到您的Podfile
pod 'react-native-fetch-blob',:path => '../node_modules/react-native-fetch-blob'自動鏈接Native Modules
react-native link使用下面的命令添加到Android AndroidManifest.xml 文件里
RNFB_ANDROID_PERMISSIONS=true react-native link如果你是非默認的項目結果,link腳本也許不生效。請參考the wiki手動鏈接包(也很簡單的)
看到這里小小的總結一下上面五步吧。要不你就1、3、4搞定,要不你就1、5搞定
對于Android 5.0或者更低版本的,授權許可外部擴展存儲
Android 6.0發布以來,授權許可機制與之前有了些許改變。有興趣的同學可以參考Official Document,我是沒興趣的!
如果介紹外部存儲擴展 (say, SD card storage) for Android 5.0 (or lower) devices,你需要添加下面代碼的到AndroidManifest.xml.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.rnfetchblobtest"android:versionCode="1"android:versionName="1.0"><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>// 添加下面的兩句<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> ...Also, if you're going to use Android Download Manager you have to add this to AndroidManifest.xml
<intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" />// 添加這一句<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/> </intent-filter>對于Android 6.0及以上
貌似不用干嘛呢
原文:
Beginning 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.
使用
import RNFetchBlob from 'react-native-fetch-blob'轉載于:https://my.oschina.net/KJhulinhua/blog/1014853
總結
以上是生活随笔為你收集整理的react-natvie-fetch-blob使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Atom ctrl+atl+b 快捷键修
- 下一篇: 【机器学习】粗糙集属性约简算法与mRMR