How to use the rn-fetch-blob.fs function in rn-fetch-blob

To help you get started, we’ve selected a few rn-fetch-blob 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 CodeRabbitYu / ShiTu / app / mobx / News / WelfareMobx.js View on Github external
saveImageWithAndroid = async (url: string) => {
    // url最后一个反斜线的位置
    const lastIndex = url.lastIndexOf('/');
    // 通过位置得到图片名称
    const imageName = url.substr(lastIndex);

    const config = {
      fileCache: true,
      path: Dirs.DCIMDir + imageName
    };

    try {
      // 下载图片
      await FetchBlob.config(config).fetch('GET', url);
      await FetchBlob.fs.scanFile([{ path: Dirs.DCIMDir + imageName, mime: '' }]);
      alert('保存成功');
    } catch (e) {
      console.log(e);
      alert('保存失败');
    }
  };
github developmentseed / observe / app / actions / map.js View on Github external
const { map: { mode } } = getState()

    // there may be other modes in which we don't want to fetch data
    if (zoom >= 16 && mode !== 'bbox') {
      // load data
      await dispatch(fetchData(visibleBounds))

      const tiles = bboxToTiles(visibleBounds)

      // load data for all visible tiles into the cache (read by selectors.getVisibleFeatures)
      for (const tile of tiles) {
        try {
          if (!cache.has(tile)) {
            // insert a placeholder to avoid doing this multiple times
            cache.set(tile, false)
            const filename = `${RNFetchBlob.fs.dirs.DocumentDir}/${tile.slice(0, 8)}/${tile}.osm.xml`

            if (await RNFetchBlob.fs.exists(filename)) {
              const data = await RNFetchBlob.fs.readFile(filename, 'utf8')
              const xmlData = XML_PARSER.parseFromString(data, 'text/xml')
              const geoJSON = osmtogeojson(filterRelations(xmlData), {
                flatProperties: true,
                wayRefs: true
              })
              cache.set(tile, geoJSON)
              dispatch({
                type: types.NEW_DATA_AVAILABLE
              })
            } else {
              // OSM XML for this tile doesn't exist (yet)
              cache.del(tile)
            }
github mattermost / mattermost-mobile / app / utils / image_cache_manager.js View on Github external
export const getCacheFile = async (name, uri) => {
    const filename = name || uri.substring(uri.lastIndexOf('/'), uri.indexOf('?') === -1 ? uri.length : uri.indexOf('?'));
    const defaultExt = `.${getExtensionFromMime(DEFAULT_MIME_TYPE)}`;
    const ext = filename.indexOf('.') === -1 ? defaultExt : filename.substring(filename.lastIndexOf('.'));

    let path = `${IMAGES_PATH}/${Math.abs(hashCode(uri))}${ext}`;

    try {
        const isDir = await RNFetchBlob.fs.isDir(IMAGES_PATH);
        if (!isDir) {
            await RNFetchBlob.fs.mkdir(IMAGES_PATH);
        }
    } catch (error) {
        // do nothing
    }

    let exists = await RNFetchBlob.fs.exists(path);
    if (!exists) {
        const pathWithDiffExt = await RNFetchBlob.fs.existsWithDiffExt(path);
        if (pathWithDiffExt) {
            exists = true;
            path = pathWithDiffExt;
        }
    }
github alphasp / pxview / src / components / UgoiraViewTouchable.js View on Github external
item: { id },
      ugoiraMeta,
    } = this.props;
    const { zipUrl } = ugoiraMeta.item;
    try {
      const ugoiraPath = `${RNFetchBlob.fs.dirs.CacheDir}/pxview/ugoira/${id}`;
      const isDir = await RNFetchBlob.fs.isDir(ugoiraPath);
      if (isDir) {
        if (!this.unmounting) {
          this.setState({
            ugoiraPath,
          });
        }
      } else {
        const downloadPath = `${
          RNFetchBlob.fs.dirs.CacheDir
        }/pxview/ugoira_zip/${zipUrl.split('/').pop()}`;
        this.task = RNFetchBlob.config({
          fileCache: true,
          appendExt: 'zip',
          key: zipUrl,
          path: downloadPath,
        }).fetch('GET', zipUrl, {
          referer: 'http://www.pixiv.net',
        });
        try {
          this.setState({
            isDownloadingZip: true,
          });
          const res = await this.task;
          if (!this.unmounting) {
            try {
github wonday / react-native-image-cache-wrapper / index.js View on Github external
async function _unlinkFile(file) {
    try {
        return await RNFetchBlob.fs.unlink(file);
    } catch (e) {
    }
}
github iotaledger / trinity-wallet / src / mobile / src / ui / views / wallet / StateExport.js View on Github external
async exportStateFile() {
        const { accounts, settings, notificationLog, t, generateAlert } = this.props;
        if (isAndroid) {
            await getAndroidFileSystemPermissions();
        }

        const path = `${
            isAndroid ? RNFetchBlob.fs.dirs.DownloadDir : RNFetchBlob.fs.dirs.CacheDir
        }/Trinity-${moment().format('YYYYMMDD-HHmm')}.txt`;

        const fs = RNFetchBlob.fs;

        try {
            const files = await Promise.all([
                fs.ls(fs.dirs.DocumentDir),
                fs.ls(fs.dirs.CacheDir),
                fs.ls(fs.dirs.MainBundleDir),
            ]);

            const fileExists = await fs.exists(path);
            if (fileExists) {
                fs.unlink(path);
            }
            await fs.createFile(
                path,
                serialise(
                    {
github wcandillon / react-native-img-cache / src / index.tsx View on Github external
}).catch(() => {
                cache.downloading = false;
                RNFetchBlob.fs.unlink(path);
            });
        }
github guardian / editions / projects / Apps / editionsSrc / src / helpers / files.ts View on Github external
export const ensureDirExists = (dir: string): Promise =>
    RNFetchBlob.fs.mkdir(dir).catch(() => Promise.resolve())
github CodeRabbitYu / ShiTu / app / mobx / News / WelfareMobx.js View on Github external
/**
 * @flow
 * Created by Rabbit on 2018/5/4.
 */

import { observable, action, runInAction } from 'mobx';
import type { RTGankData, RTWeal, RTWealResult } from '../../servers/News/interfaces';
import { fetchWelfareData } from '../../servers/News';
import { System } from '../../utils';
import { CameraRoll } from 'react-native';
import { ConfigStore } from '../../store/ConfigStore';
import FetchBlob from 'rn-fetch-blob';
const Dirs = FetchBlob.fs.dirs;

type loadDataType = 'refreshing' | 'load more' | string;

class WelfareMobx extends ConfigStore {
  @observable
  isRefreshing: boolean = true;
  @observable
  dataSource: Array = [];
  @observable
  page: number = 1;

  @action.bound
  saveImageWithIOS = async (url: string) => {
    try {
      await CameraRoll.saveToCameraRoll(url, 'photo');
      alert('保存成功');