How to use the rn-fetch-blob.config 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 developmentseed / observe / app / services / osm-api.js View on Github external
export async function saveDataForTile (tile) {
  const viewport = tileToBBOX(quadkeyToTile(tile))
  const bbox = [[viewport[2], viewport[3]], [viewport[0], viewport[1]]]

  const url = `${mapSlug}/?bbox=${bboxToString(bbox)}`
  const path = `${RNFetchBlob.fs.dirs.DocumentDir}/${tile.slice(0, 8)}/${tile}.osm.xml`
  const tmpPath = `${path}.tmp`
  const rsp = await RNFetchBlob.config({
    followRedirect: false,
    path: tmpPath
  }).fetch('GET', url, {
    ...await getOAuthHeaders(url)
  })

  if (rsp.info().status !== 200) {
    console.log(`${url} failed with status code ${rsp.info().status}: ${await rsp.text()}`)
    throw new Error(`Request to ${url} failed with status code ${rsp.info().status}`)
  }
  const stat = await RNFetchBlob.fs.stat(rsp.path())

  // once we are sure the file is fully downloaded, we move it to its final location
  // so that readers never get a half-written file.
  try {
    await RNFetchBlob.fs.unlink(path)
github XingXiaoWu / react-native-template-wx / src / utils / net / FetchUtil.js View on Github external
downLoadBundle(url) {
        let name = this.getFileName(url)
        let dirs = RNFetchBlob.fs.dirs.DocumentDir
        let path = dirs + "/" + name
        RNFetchBlob
            .config({
                // 有文件默认覆盖
                overwrite:true,
                // 下载的指示器,ios执行
                indicator:true,
                // 允许自建ssl通信
                trusty:true,
                // add this option that makes response data to be stored as a file,
                // this is much more performant.
                fileCache: true,
                // 拓展
                appendExt: 'jsbundle',
                // 路径
                path:path

            })
github alphasp / pxview / src / components / UgoiraViewTouchable.js View on Github external
} = 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 {
              const path = await unzip(res.path(), ugoiraPath);
              this.setState({
github kiwicom / mobile / packages / assets / src / AssetsDownloader.js View on Github external
url: string,
  overwriteExisting?: boolean = false,
): Promise => {
  const { DocumentDir } = RNFetchBlob.fs.dirs;
  if (DocumentDir === undefined) {
    throw Error('Cannot access DocumentDir.');
  }

  try {
    const path = `${DocumentDir}/${fileName}`;

    if (!overwriteExisting && (await RNFetchBlob.fs.exists(path))) {
      return `file:///${path}`;
    }

    const response = await RNFetchBlob.config({
      path,
    }).fetch('GET', url);

    return response.path();
  } catch (err) {
    console.warn(err);
    return null;
  }
};
github wcandillon / react-native-img-cache / src / index.tsx View on Github external
private download(cache: CacheEntry) {
        const {source} = cache;
        const {uri} = source;
        if (!cache.downloading) {
            const path = this.getPath(uri, cache.immutable);
            cache.downloading = true;
            const method = source.method ? source.method : "GET";
            cache.task = RNFetchBlob.config({ path }).fetch(method, uri, source.headers);
            cache.task.then(() => {
                cache.downloading = false;
                cache.path = path;
                this.notify(uri);
            }).catch(() => {
                cache.downloading = false;
                RNFetchBlob.fs.unlink(path);
            });
        }
    }
github futurepress / epubjs-rn / src / Streamer.js View on Github external
add(bookUrl) {
    let uri = new Uri(bookUrl);
    const filename = this.filename(bookUrl);

    return RNFetchBlob
      .config({
        fileCache : true,
        path: Dirs.DocumentDir + '/' + filename
      })
      .fetch("GET", bookUrl)
      .then((res) => {
        const sourcePath = res.path();
        const targetPath = `${Dirs.DocumentDir}/${this.root}/${filename}`;
        const url = `${this.serverOrigin}/${filename}/`;

        return unzip(sourcePath, targetPath)
          .then((path) => {

            this.urls.push(bookUrl);
            this.locals.push(url);
            this.paths.push(path);
github mattermost / mattermost-mobile / app / components / file_upload_preview / file_upload_item / file_upload_item.js View on Github external
};

        const data = [
            {name: 'channel_id', data: channelId},
            {name: 'client_ids', data: file.clientId},
            fileInfo,
        ];

        Client4.trackEvent('api', 'api_files_upload');

        const certificate = await mattermostBucket.getPreference('cert');
        const options = {
            timeout: 10000,
            certificate,
        };
        this.uploadPromise = RNFetchBlob.config(options).fetch('POST', Client4.getFilesRoute(), headers, data);
        this.uploadPromise.uploadProgress(this.handleUploadProgress);
        this.uploadPromise.then(this.handleUploadCompleted).catch(this.handleUploadError);
    };
github mattermost / mattermost-mobile / app / screens / image_preview / downloader.android.js View on Github external
await RNFetchBlob.fs.cp(path, dest);
                }
            } else if (isDocument(data)) {
                const path = getLocalFilePathFromFile(DOCUMENTS_PATH, file);
                const exists = await RNFetchBlob.fs.exists(path);

                if (exists) {
                    downloadFile = false;
                    await RNFetchBlob.fs.cp(path, dest);
                }
            }

            if (downloadFile) {
                const imageUrl = Client4.getFileUrl(data.id);

                const task = RNFetchBlob.config({
                    fileCache: true,
                    addAndroidDownloads: {
                        useDownloadManager: true,
                        notification: true,
                        path: dest,
                        title: `${file.caption} ${title}`,
                        mime: data.mime_type,
                        description: data.name,
                        mediaScannable: true,
                    },
                }).fetch('GET', imageUrl, {
                    Authorization: `Bearer ${Client4.token}`,
                    'X-Requested-With': 'XMLHttpRequest',
                });

                await task;
github guardian / editions / projects / Apps / editionsSrc / src / helpers / files.ts View on Github external
export const downloadNamedIssueArchive = async (
    localIssueId: Issue['localId'],
    assetPath: string,
) => {
    const apiUrl = await getSetting('apiUrl')
    const zipUrl = `${apiUrl}${assetPath}`
    const returnable = RNFetchBlob.config({
        fileCache: true,
        overwrite: true,
        IOSBackgroundTask: true,
    }).fetch('GET', zipUrl)
    return {
        promise: returnable.then(async res => {
            await prepFileSystem()
            await ensureDirExists(FSPaths.issueRoot(localIssueId))
            return res
        }),
        cancel: returnable.cancel,
        progress: returnable.progress,
    }
}
github esteemapp / esteem-mobile / src / components / postElements / body / view / postBodyView.js View on Github external
const _downloadImage = async uri => {
    return RNFetchBlob.config({
      fileCache: true,
      appendExt: 'jpg',
    })
      .fetch('GET', uri)
      .then(res => {
        let status = res.info().status;

        if (status == 200) {
          return res.path();
        } else {
          Promise.reject();
        }
      })
      .catch(errorMessage => {
        Promise.reject(errorMessage);
      });