Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the files from Google Drive? #5

Open
ElangoPrince opened this issue Mar 20, 2019 · 1 comment
Open

How to get the files from Google Drive? #5

ElangoPrince opened this issue Mar 20, 2019 · 1 comment

Comments

@ElangoPrince
Copy link

ElangoPrince commented Mar 20, 2019

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);
    })

@francologic
Copy link

francologic commented May 21, 2021

Just in case somebody still need it:
i'm using react-native-google-drive-api-wrapper
and react-native-fs

After initializing Gdrive (see google-drive-api-wrapper docs) you need to get the folderId, just in case you placed your file in any folder

let folderId = await GDrive.files.safeCreateFolder({
                name: "MyFolder",
                parents: ["root"]
            })

then, use Gdrive's getId to find your file id

let myFileId= await GDrive.files.getId(
                    `myFileName`,
                    [folderId ],
                )

Make sure the folder where you want to place your file exists with RNFS

 await RNFS.exists(`${RNFS.DocumentDirectoryPath}/myFolder/`).then(async exists => {
                    if (!exists) {
                        await RNFS.mkdir(`${RNFS.DocumentDirectoryPath}/myFolder/`)
                    }
})

Finally, you can download your data:

GDrive.files.download(fileId, { toFile: `${RNFS.DocumentDirectoryPath}/myFolder/filename.json` }, { alt: "media" }).promise.then(async (res) => {
                       if (res.statusCode == 200) {
                           myFileContent = await RNFS.readFile(${RNFS.DocumentDirectoryPath}/myFolder/filename.json, 'utf8')
                          console.log(myFileContent)
                       } else {
                           throw new Error("Error")
                       }
                   })

stvkoch pushed a commit to stvkoch/react-native-cloud-fs that referenced this issue Apr 27, 2023
* Update build.gradle

* Delete CopyToGoogleDriveTask.java

* Create DriveServiceHelper.java

* Delete GoogleDriveApiClient.java

* Update RNCloudFsModule.java

* bump to v2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants