Giter Club home page Giter Club logo

react-native-cloud-fs's Introduction

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';
const update = false;

RNCloudFs.copyToCloud({
  sourcePath: sourceUri, 
  targetPath: destinationPath, 
  mimeType, 
  scope,
  update
})
  .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)

update: a boolean to specify if we want to update an existing item instead of creating a new one

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)

readFileContent (options)

Reads a file content. 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.readFileContent({targetPath: path, scope: scope})
  .then((res) => {
    console.log("it worked", res);
  })
  .catch((err) => {
    console.warn("it failed", err);
  })

targetPath: a path representing a file which content you want to read

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

react-native-cloud-fs's People

Contributors

gcoro avatar joegoodall1 avatar likea-boss avatar npomfret avatar viktoriiamialo avatar viktoriyamyalo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-cloud-fs's Issues

[Android] Duplicate Class Error

Works fine on IOS but on android it throws a duplicate class error. I have tried on Android studio but it couldn't detect the file from where the error raised.

My React-native environment:
"react-native": "^0.70.6"
"react-native-cloud-fs":^2.7.0
android gradle plugin version: 7.2.2
Gradle-version- 7.5.1


React Native Code:

const IcloudBackUp = () => {
const onPressHandler = async () => {
try {
// Store it on the FS first
const path = ${RNFS.DocumentDirectoryPath}/${filename};
await RNFS.writeFile(path, 'Lorem ipsum dolor sit amet', 'utf8');

  const sourceUri = {path};
  const mimeType = 'text/plain';
  const result = await RNCloudFs.copyToCloud({
    mimeType,
    scope,
    sourcePath: sourceUri,
    targetPath: destinationPath,
  });
  console.log('Result of setting items to iCloud', result);
} catch (error) {
  console.log('Error in setting items to iCloud', error);
}

};


app/build.gradle:
//Added this
compile ('com.google.android.gms:play-services-drive:10.2.0') {
force = true;
}
//Tried with implementation also
compile ('com.google.android.gms:play-services-drive:10.2.0') {
force = true;
}


IOS setup is same as described in the documentation

iCloud Drive capability no longer the same

The iCloud Drive capability no longer exists on the capabilities page in the lastest Xcode. Do you know how to add it? And if so maybe you could update the get started doc. Also I could not quite figure out how to add the code to the info.plist file. In Xcode the file has fields rather than just code ๐Ÿค” It would be nice to see this as well more in-depth in the doc.

Exception thrown

Hi, thanks for the lib

I'm having some issue getting started, an exception is thrown, any tip?

RNCloudFs.copyToCloud({
  sourcePath: DATABASE_PATH,
  targetPath: 'test/folder/file.db',
  scope: 'visible'
})
  .then((path) => {
    console.log("it worked", path)
  })
  .catch((err) => {
    console.warn("it failed", err)
  })

simulator screen shot aug 3 2017 1 35 32 am

Any idea?

How to get the files from Google Drive?

Get the file or selected file path from google drive. state any example for that?

my code:

const sourceUri = {uri: 'https://drive.google.com'};
  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);
    })

Auto-linking support

Can I add .podspec file for auto-linking support for react-native 0.60+ on iOS?

problem occurred evaluating project ':rn-cloud-fs'.

FAILURE: Build failed with an exception.

  • Where:
    Build file '/Users/surajsharma/Desktop/Diamante/DiamWallet/DiamWallet_v2/dc_diam_wallet_app_v2_react_native/node_modules/rn-cloud-fs/android/build.gradle' line: 47

  • What went wrong:
    A problem occurred evaluating project ':rn-cloud-fs'.

Cannot set the value of read-only property 'force' for DefaultExternalModuleDependency{group='com.google.android.gms', name='play-services-auth', version='17.0.0', configuration='default'} of type org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.