How to use the react-native-fs.ExternalDirectoryPath function in react-native-fs

To help you get started, we’ve selected a few react-native-fs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github digidem / mapeo-mobile / src / frontend / api.spec.js View on Github external
expect.assertions(5);
    nodejs.start = jest.fn();
    // This mocks the initial heartbeat from the server
    nodejs.channel.once = jest.fn((_, handler) => handler());
    // This mocks the server to immediately be in "Listening" state
    nodejs.channel.addListener = jest.fn((_, handler) =>
      handler(Constants.LISTENING)
    );
    nodejs.channel.post = jest.fn();
    const api = new Api({ baseUrl: "__URL__" });
    await expect(api.startServer()).resolves.toBeUndefined();
    expect(nodejs.start.mock.calls.length).toBe(1);
    expect(nodejs.start.mock.calls[0][0]).toBe("loader.js");
    expect(nodejs.channel.post.mock.calls.length).toBe(2);
    expect(nodejs.channel.post.mock.calls[1][1]).toBe(
      RNFS.ExternalDirectoryPath
    );
  });
github banli17 / react-native-update-app / index.js View on Github external
androidUpdate = async () => {
        let _this = this
        const {url, filename, version} = this.fetchRes
        // 按照目录/包名/文件名 存放,生成md5文件标识

        this.filePath = `${RNFS.ExternalDirectoryPath}/${filename}${version}.apk`

        // 检查包是否已经下载过,如果有,则直接安装
        let exist = await RNFS.exists(this.filePath)
        if (exist) {
            RNUpdateApp.install(this.filePath)
            this.hideModal()
            return
        }

        // 下载apk并安装
        RNFS.downloadFile({
            fromUrl: url,
            toFile: this.filePath,
            progressDivider: 2,   // 节流
            begin(res) {
                _this.jobId = res.jobId   // 设置jobId,用于暂停和恢复下载任务
github cllemon / reactNativeDemo / app / common / utils.js View on Github external
export const generateLocalPath = async (url, format) => {
  try {
    const ABSOLUTEPATH = VALUE.ios
      ? REACTNATIVEFS.LibraryDirectoryPath
      : REACTNATIVEFS.ExternalDirectoryPath;
    const STORAGEPATH = `${ABSOLUTEPATH}/${Date.now()}.${format}`;
    const { statusCode } = await REACTNATIVEFS.downloadFile({
      fromUrl: url,
      toFile: STORAGEPATH
    }).promise;
    if (statusCode === 200) return `file://${STORAGEPATH}`;
    return false;
  } catch (error) {
    console.error('生成本地路径异常', error);
  }
};
github yimankaing / react-native-bluetooth-printer / App.js View on Github external
import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View,
  Button,
  NativeModules,
} from 'react-native';
import ViewShot from "react-native-view-shot";
import RNFS from "react-native-fs";

const PrinterManager = NativeModules.PrinterManager;
const imageType = "png";
const imagePath = `${RNFS.ExternalDirectoryPath}/image.${imageType}`;


export default class App extends React.Component {
  constructor(props) {
    super(props);
  }

  captureView = async () => {
    this.refs.viewShot.capture().then(uri => {
      RNFS.moveFile(uri, imagePath)
        .then((success) => {
          console.log('FILE MOVED!');
          //this.printViewShot(imagePath)
        })
        .catch((err) => {
          console.log(err.message);
github d2rivendell / react-native-GCore / app / components / other / timeLine / TimeLine.js View on Github external
_download(){
        const {timeLine,} = this.props
        var localPath = RNFS.LibraryDirectoryPath + '/' + this.state.pageInfo.id + '.mp3'
        if(Platform.OS === 'android'){
            localPath = RNFS.ExternalDirectoryPath + '/' + this.state.pageInfo.id + '.mp3'
        }
        let downloadManager = new DownloadManager()

        if(downloadManager.isDownloading ){
            Alert.alert('提示','已有任务在队列中',[{text:'确定',onPress:()=>{console.log('sure')} }])
            return
        }

        console.log(localPath)
        let starage = new MyStorage()
        starage.getAudioInfo(this.state.pageInfo.id,(res)=>{
            if(res){
                Alert.alert('提示','资源已经下载',[{text:'确定',onPress:()=>{console.log('sure')} }])
            }else{
                Alert.alert('提示','开始下载',[{text:'确定',onPress:()=>{console.log('sure')} }])
                downloadManager.downloadFile(this.state.pageInfo.media.mp3[0],localPath,timeLine,this.state.pageInfo)
github alexjoverm / react-native-gps-logger / src / Home / index.js View on Github external
Text,
  View,
  Alert,
  Picker,
  Button,
} from "react-native";
import RNFS from "react-native-fs";
import js2xmlparser from "js2xmlparser";

import Stats from "./Stats";
import Record from "./Record";
import tracking, { trackingConfigs } from "./tracking";
import { toKnots, stateFromLocation } from "./utils";

const jsToXml = js2xmlparser.parse;
const filePath = RNFS.ExternalDirectoryPath + "/route.gpx";

const getDefaultState = () => ({
  latitude: "--",
  longitude: "--",
  distance: "--",
  accuracy: "--",
  cog: "--",
  speed: "--",
});

export default class App extends React.Component {
  state = {
    trackingRunning: false,
    mode: "walk",
    ...getDefaultState(),
  };
github crownstone / CrownstoneApp / js / util / FileUtil.ts View on Github external
getPath: function(filename? : string) {
    let targetPath = Platform.OS === 'android' ? RNFS.ExternalDirectoryPath : RNFS.DocumentDirectoryPath;

    if (filename) {
      if (targetPath[targetPath.length-1] !== '/') {
        targetPath += '/';
      }
      targetPath += filename;
    }
    return targetPath;
  },