RobinBobin / react-native-google-drive-api-wrapper

This wrapper facilitates the use of the Google Drive API in React Native projects.
110 stars 43 forks source link

i'm trying to upload sqlite db #93

Closed Ibrahim-97 closed 10 months ago

Ibrahim-97 commented 1 year ago
const backupToDrive = async () => {
    try {

      const file = await FileSystem.readAsStringAsync(
        FileSystem.documentDirectory + "SQLite/mydb.db",
        {
          encoding: FileSystem.EncodingType.Base64
        }
      )

      const gdrive = new GDrive()
      gdrive.accessToken = (await GoogleSignin.getTokens()).accessToken

      // console.log(await gdrive.files.list())

      const id = await gdrive.files.newMultipartUploader()
      .setData(file, MimeTypes.BINARY)
      .setIsBase64(true)
      .setRequestBody({
        name: `AVbackup-[${moment().format('MMMM-Do-YYYY-h:mm:ssa')}].db`,
        headers: ['Content-Transfer-Encoding: base64']
      }).execute()

    } catch (error) {
      console.error(error)
    }
}

error : [AbortError: Aborted]

RobinBobin commented 1 year ago

Have a look at fetchTimeout.

I doubt you need headers: ['Content-Transfer-Encoding: base64']

RobinBobin commented 1 year ago

I also think MimeTypes.TEXT should be used instead of MimeTypes.BINARY.

ahmedsweng commented 11 months ago

@Ibrahim-97 Don't forget to add google drive scopes in your sign in with google like this:

  GoogleSignin.configure({
    webClientId:
      "*******************************************************************",
    scopes: [
      "https://www.googleapis.com/auth/drive.file",
      "https://www.googleapis.com/auth/drive.appdata",
    ],
  });

and also add them in you google cloud console