Closed singhlovey closed 6 years ago
Hi there! Thanks a lot for the feedback, it's very pleasant to here someone uses my plugin. It so happened now I dont't have time to literally turn on my notebook, I even don't work now. I really am interested in addressing your issue, but I kindly ask you to wait a bit, please. Sincerely, Robin. среда, 14 марта 2018г., 10:50 +03:00 от singhlovey notifications@github.com :
Hi, First of all this plugin is very useful to interact with google drive and upload files to the same after authentication. I am able to upload normal text file to google drive. But now point is how to upload PDF file to google drive. Do I need to convert its content to base64 and then upload or is there any other way. let contents = " http://xyz.com/ " + this.state.pdf; GDrive.files.createFileMultipart( contents, "application/pdf", { name: "My file" }).then((data) => { console.log('reponsee in then ' + JSON.stringify(data)); }); Contents variable contain root path where pdf file is stored. Please help and let me know if any other information is required. Thanks — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or mute the thread .
Please have a look here (section createFileMultipart()
).
const contents = "My text file contents";
// or
const contents = [10, 20, 30];
GDrive.files.createFileMultipart(
contents,
"corresponding mime type", {
parents: ["root"],
name: "My file"
});
It seems to me contents
must be a binary buffer for your case, not a path to a file.
Hi RobinBobin,
OK. So you mean I need to fetch content of PDF file and convert it into the encoded form and pass it into contents variable. Right?
If it is so, can you please suggest any plugin, which will convert my pdf content in the form which I can pass it into contents variable and upload it at google dive.
Thanks for your help
Lovedeep Singh
On Fri, Mar 16, 2018 at 1:40 AM, RobinBobin notifications@github.com wrote:
Please have a look here https://github.com/RobinBobin/react-native-google-drive-api-wrapper#gdriveapiwFiles (section createFileMultipart()).
const contents = "My text file contents"; // or const contents = [10, 20, 30];
GDrive.files.createFileMultipart( contents, "corresponding mime type", { parents: ["root"], name: "My file" });
It seems to me contents must be a binary buffer for your case, not a path to a file.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/RobinBobin/react-native-google-drive-api-wrapper/issues/1#issuecomment-373507189, or mute the thread https://github.com/notifications/unsubscribe-auth/AgcsNY8ccB4f_Gq2w2SmRHwAHX_x3Bzwks5tesq-gaJpZM4Sp-Kq .
Exactly. You must get the contents of a file. There's no special encoded form, it's just a binary buffer (a stream of bytes). I use react-native-fs for this.
Hi, for future readers this might help, as it worked for me.
I converted file to base 64 using react-native-fs package
let fileContent = await RNFS.readFile(localFilePath, 'base64');
and then made following request
await gdrive.files
.newMultipartUploader()
.setData(fileContent, MimeTypes.PDF)
.setIsBase64(true)
.setRequestBody({
name: fileName, <--- file name with extension for e.g., myfile.pdf
parents: ['root']
})
.execute();
Hi,
First of all this plugin is very useful to interact with google drive and upload files to the same after authentication. I am able to upload normal text file to google drive.
But now the point is how to upload PDF file to google drive. Do I need to convert its content to base64 and then upload or is there any other way.
let contents = "http://xyz.com/" + this.state.pdf;
GDrive.files.createFileMultipart( contents, "application/pdf", { name: "My file" }).then((data) => { console.log('reponsee in then ' + JSON.stringify(data)); });
"contents" variable contain root path where pdf file is stored.
Please help and let me know if any other information is required.
Thanks