npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-cloud-fs

v2.7.0

Published

A react-native library for reading and writing files to _iCloud Drive_ (iOS) and _Google Drive_ (Android).

Downloads

83

Readme

react-native-cloud-fs

A react-native library for reading and writing files to iCloud Drive (iOS) and Google Drive (Android).

Getting started

Usage

import RNCloudFs from 'react-native-cloud-fs';

fileExists (options)

Returns a promise which when resolved returns a boolean value indicating if the specified path already exists.

const destinationPath = "foo-bar/docs/info.pdf";
const scope = 'visible';

RNCloudFs.fileExists({
  targetPath: destinationPath, 
  scope: scope
})
  .then((exists) => {
    console.log(exists ? "this file exists" : "this file does not exist");
  })
  .catch((err) => {
    console.warn("it failed", err);
  })

targetPath: a path

scope: determines if the user-visible documents (visible) or the app-visible documents (hidden) are searched for the specified path

copyToCloud (options)

Copies the content of a file (or uri) to the target file system. The files will appear in a either a user visible directory, or a dectory that only the app can see. The directory is named after destinationPath. The directory hierarchy for the destination path will be created if it doesn't already exist. If the target file already exists it a new filename is chosen and returned when the promise is resolved.

const sourceUri = {uri: 'https://foo.com/bar.pdf'};
const destinationPath = "foo-bar/docs/info.pdf";
const mimeType = null;
const scope = 'visible';

RNCloudFs.copyToCloud({
  sourcePath: sourceUri, 
  targetPath: destinationPath, 
  mimeType: mimeType, 
  scope: scope
})
  .then((path) => {
    console.log("it worked", path);
  })
  .catch((err) => {
    console.warn("it failed", err);
  })

sourceUri: object with any uri or an absolute file path and optional http headers, e.g:

  • {path: '/foo/bar/file.txt'}
  • {uri: 'file://foo/bar/file.txt'}
  • {uri: 'http://www.files.com/foo/bar/file.txt', 'http-headers': {user: 'foo', password: 'bar'}} (http-headers are android only)
  • {uri: 'content://media/external/images/media/296'} (android only)
  • {uri: 'assets-library://asset/asset.JPG?id=106E99A1-4F6A-45A2-B320-B0AD4A8E8473&ext=JPG'} (iOS only)

targetPath: a relative path including a filename under which the file will be placed, e.g:

  • my-cloud-text-file.txt
  • foo/bar/my-cloud-text-file.txt

mimeType: a mime type to store the file with or null (android only) , e.g:

  • text/plain
  • application/json
  • image/jpeg

scope: a string to specify if the user can access the document (visible) or not (hidden)

listFiles (options)

Lists files in a directory along with some file metadata. The scope determines if the file listing takes place in the app folder or the public user documents folder.

const path = "dirA/dirB";
const scope = 'hidden';

RNCloudFs.listFiles({targetPath: path, scope: scope})
  .then((res) => {
    console.log("it worked", res);
  })
  .catch((err) => {
    console.warn("it failed", err);
  })

targetPath: a path representing a folder to list files from

scope: a string to specify if the files are the user-visible documents (visible) or the app-visible documents (hidden)

Android

After following the instructions in Getting started I recommend using react-native-google-signin to authenticate the user, especially if you need additional scopes besides auth/drive.file which is the only scope this package requests, and let that package handle auth.

Example of usage on Android:

import { Platform } from 'react-native';
import { GoogleSignin, statusCodes } from '@react-native-community/google-signin';
import RNCloudFS from 'react-native-cloud-fs';

if (Platform.OS === 'android') {
  GoogleSignin.configure({
    scopes: [
      'https://www.googleapis.com/auth/userinfo.profile',
      'https://www.googleapis.com/auth/userinfo.email',
      'https://www.googleapis.com/auth/drive.file',
      // other scopes your app needs
    ],
    webClientId: '...' // you may not need this depending on scopes,
    offlineAccess: true,
    forceConsentPrompt: true,
  });

  // Ensure play services exist. Cannot sign in otherwise. If unavailable, this
  // will show a modal asking the user to get play services before continuing.
  await GoogleSignin.hasPlayServices({
    showPlayServicesUpdateDialog: true
  });

  // If user is already signed in, don't need to call signIn again
  const isSignedIn = await GoogleSignin.isSignedIn();
  if (!isSignedIn) {
    await GoogleSignin.signIn();
  }

  // Syncs signed in state to RNCloudFS
  await RNCloudFS.loginIfNeeded();
  
  // Now you can copy to cloud
  await RNCloudFS.copyToCloud({
    sourcePath: { path: 'some/path.txt' },
    targetPath: `some/path.txt`,
    scope: 'visible'
  });
}