Closed przbadu closed 2 years ago
I would try converting base64 to binary before uploading. I guess any RN project has the base64-js dependency. And only then upload to GDrive, setting whatever mime type you want.
Thank you @RobinBobin for quick response, I will try it.
Thank you so much @RobinBobin , My stupid mistake, RNFS.readFile
was missing await
call and trying to treat it as base64.
Here is the solution if anyone is wondering:
async uploadToDrive(): Promise<void> {
try {
const mimeType = MimeTypes.BINARY;
const localDBFilePath = '/data/data/<my-package-name>/demo.db';
const fileToBackup = await RNFS.readFile(localDBFilePath, 'base64'); // I forget to add await call here
const fileMetadata = {
name: 'test.db',
MimeTypes: mimeType,
};
const result = await this.gdrive.files
.newMultipartUploader()
.setData(fileToBackup, mimeType)
.setIsBase64(true) // this is base64 content, so set this to true. Or if you want to pass binary content as @RobinBobin suggested, then you don't need to set this.
.setRequestBody(fileMetadata)
.execute();
console.log('file uploaded to Drive: ', result.id);
} catch (error: any) {
alert('Error: ' + error.message);
}
}
Glad you got it working :slightly_smiling_face: .
:smile: shame on me for not noticing the missing await
and completely forgetting about .setIsBase64()
:flushed:
Hi, I am really struggling to upload my sqlite backup file to google drive. If I do local backup, everything works fine, and I can view content of my sqlite backup in SQLite Viewer.
Where as if I try to upload that file to google drive using this library, I always get 0 byte sqlite file uploaded in google drive, which do not have any content in it.
Here is what I am doing right now:
If anyone can help me find, what I am doing wrong would be appreciated.
Screenshots: