How to use the react-native-fs.moveFile 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 josephroquedev / campus-guide / src / util / Configuration.ts View on Github external
}

    const configRowUpdates: ConfigFile[] = [];

    // Delete the old configuration files, move the new ones
    for (const update of configDetails.files) {
      // Delete the file if it exists
      const targetLocation = `${CONFIG_DIRECTORY}${CONFIG_SUBDIRECTORIES[update.type]}${update.name}`;
      const tempLocation = `${TEMP_CONFIG_DIRECTORY}${update.name}`;

      const exists = await RNFS.exists(targetLocation);
      if (exists) {
        await RNFS.unlink(targetLocation);
      }

      await RNFS.moveFile(
        tempLocation,
        targetLocation
      );

      configRowUpdates.push(update);
    }

    // Delete temporary downloads
    await RNFS.unlink(TEMP_CONFIG_DIRECTORY);

    // Update config versions in database
    await Database.updateConfigVersions(configRowUpdates);
    await setConfigLastUpdatedAt(configDetails.lastUpdatedAt);

    configurationInitialized = false;
    await init();
github celo-org / celo-monorepo / packages / mobile / src / utils / LogUploader.ts View on Github external
static async upload(
    logFilePath: string,
    uploadPath: string,
    uploadFileName: string
  ): Promise {
    const tmpFilePath = logFilePath + '.tmp'
    await RNFS.moveFile(logFilePath, tmpFilePath)
    // Don't "await" here. While everything else in this async method is relatively fast, data upload can be slow
    // and we don't want to block the user from using the app.
    return FirebaseLogUploader.uploadLogsToFirebaseStorage(tmpFilePath, uploadPath, uploadFileName)
  }
github xaphod / LaneChange / app / components / camera.js View on Github external
const response = await ImageResizer.createResizedImage(uri, 2000, 2000, 'JPEG', 60)
      .catch((err) => {
        consolelog('DEBUG camera: resize ERROR:');
        consolelog(err);
        onPhotoTaken(undefined, new Error('Could not take a photo: there was an error resizing the photo.'));
        failed = true;
      });
    if (failed) { return; }

    await RNFS.unlink(uri)
      .catch((err) => { // not a failure
        consolelog(`DEBUG camera: could not delete full-sized photo: ${err}`);
      });

    const destPathResized = photoPath() + '/' + destFilenameResized;
    await RNFS.moveFile(response.uri, destPathResized)
      .catch((err) => {
        consolelog('DEBUG camera: move2 ERROR:');
        consolelog(err);
        onPhotoTaken(undefined, new Error('Could not take a photo: could not move the resized photo into its folder.'));
        failed = true;
      });
    if (failed) { return; }

    photo.uri = destPathResized;
    photo.filename = destFilenameResized;
    onPhotoTaken(photo);
  };
github prscX / react-native-photo-editor / Example / App.js View on Github external
.then(resp => {
                RNFS.moveFile(resp.path(), photoPath)
                    .then(() => {
                        console.log('FILE WRITTEN!')
                    })
                    .catch(err => {
                        console.log(err.message)
                    })
            })
            .catch(err => {
github yimankaing / react-native-bluetooth-printer / App.js View on Github external
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 EdgeApp / edge-react-gui / src / util / logger.js View on Github external
async function rotateLogs () {
  try {
    if (await RNFS.exists(path3)) {
      await RNFS.unlink(path3)
    }
    if (await RNFS.exists(path2)) {
      await RNFS.moveFile(path2, path3)
    }
    if (await RNFS.exists(path1)) {
      await RNFS.moveFile(path1, path2)
    }
    await RNFS.writeFile(path1, '')
  } catch (e) {
    global.clog(e)
  }
}
github GantMan / nicornot / NicOrNotApp / src / lib / fetchModel.js View on Github external
const mlc = modelName + '.mlmodelc'
  const ml = modelName + '.mlmodel'
  const compiledPath = RNFS.DocumentDirectoryPath + '/' + mlc
  if (await RNFS.exists(compiledPath)) {
    return compiledPath
  }
  const toFile = RNFS.TemporaryDirectoryPath + ml
  if (!(await RNFS.exists(toFile))) {
    const { promise, _jobId } = RNFS.downloadFile({
      fromUrl: modelURL,
      toFile: toFile
    })
    await promise
  }
  const tempPath = await compileModel(toFile)
  await RNFS.moveFile(tempPath, compiledPath)
  return 'file://' + compiledPath
}
github crownstone / CrownstoneApp / js / util / FileUtil.ts View on Github external
return new Promise((resolve, reject) => {
          RNFS.moveFile(from, to)
            .then(() => {
              resolve(to);
            });
        })
      })
github crownstone / CrownstoneApp / js / views / startupViews / Login.tsx View on Github external
.then(() => {
                LOGi.info("Login: uploadedImage. Now start moving.");
                return RNFS.moveFile(file.path, newPath);
              })
              .then(() => {
github textileio / photos / App / Sagas / NodeLifecycle.ts View on Github external
async function moveTextileFiles() {
  const files = await RNFS.readDir(RNFS.DocumentDirectoryPath)
  for (const file of files) {
    if (file.path !== REPO_PATH && file.name !== 'RCTAsyncLocalStorage_V1') {
      await RNFS.moveFile(file.path, `${REPO_PATH}/${file.name}`)
    }
  }
}