0

I am trying to upload a pdf file to google drive using the API. In the Google drive api documentation the only way to pass the file is by indicating the path on on your local pc with the use of fs.createReadStream. google drive api documentation

However in my front end, i'm getting the file as a pdf with the help of jspdf and autotable:

const doc = new jsPDF('portrait', 'px', 'a4') as jsPDFWIthPlugin
doc.autoTable({
  head: [["Payment", "Payment Date", "Loan Amount", "Amortization Payment", "Balance"]],
  body: this.scheduleArray
})
this.pdf = doc.output("blob")
this.data = doc.output('datauristring')
doc.save("table.pdf")

In the google drive api documentation it says I can upload to a google drive by specifying the local path for example fs.createReadStream('files/photo.jpg). But what if I want to upload a pdf that is for example in the form of a base64 encoded string like a data URI. How can files like that be uploaded using the google drive api?

Tanaike
  • 181,128
  • 11
  • 97
  • 165
TJ37
  • 35
  • 1
  • 7
  • I cannot understand about `Is there a way I can replace fs.createReadStream('files/photo.jpg') in the body of the google api with this.data I got from my front end?`. I apologize for this. Do you want to convert the JPEG data to PDF? – Tanaike Jan 06 '21 at 02:01
  • In the google drive api documentation it says I can upload to a google drive by specifying the local path for example fs.createReadStream('files/photo.jpg). But what if i want to upload a pdf that is for example in the form of a base64 encoded string like a data URI. How can files like that be uploaded using the google drive api? – TJ37 Jan 06 '21 at 13:39
  • Sorry for not being clear. I edited the question – TJ37 Jan 06 '21 at 13:48
  • 1
    Thank you for replying. In your situation, was this answer useful? https://stackoverflow.com/a/58253659 If you have the issue, feel free to tell me. – Tanaike Jan 07 '21 at 00:42
  • 1
    Yes this solution worked!. Thank you very much – TJ37 Jan 07 '21 at 00:52
  • Thank you for replying. I'm glad your issue was resolved. From your replying, I edit the tags and flagged this as the duplicate of https://stackoverflow.com/q/58251141 – Tanaike Jan 07 '21 at 00:54
  • 1
    yes the solution https://stackoverflow.com/a/58253659/10567291 from that post solved my issue – TJ37 Jan 07 '21 at 01:01

0 Answers0