1

I am using "The Google Picker API" with asp.net web application to retrieve a file saved in Google drive and convert it to PDF using google export, then I want to save the PDF file to web server I am getting the download link of Google drive file converted to PDF in this format

https://docs.google.com/spreadsheets/d/**an-id-here***/export?format=pdf

The link is working fine and I'm getting the file downloaded.

But I want to save the file to my wb server using a http handler which I am calling from javascript When I send the download link to the Htpp handler, the file saved to the server is corrupted But when I use a url like this one http://www.africau.edu/images/default/sample.pdf the file is saved correctly to my web server

I'm using this code to save the pdf fil into the server

Using client = New System.Net.WebClient()
            client.DownloadFile(url, tofile)
End Using

My question is:

  • is there a way to get url for the pdf file rather then a download link
  • Or if not possible, is there a way to save the file into the web server using this download link ?
Kemal AL GAZZAH
  • 967
  • 6
  • 15
  • Do you need to log in to Google to access these spreadsheets? – James Mar 31 '22 at 15:24
  • I am using google picker, I can access these spreadsheet without problem, but I want to get url to the file converted to PDF – Kemal AL GAZZAH Mar 31 '22 at 15:28
  • Yeah I just wondered if your .NET server code will also need to log into google to have access to these spreadsheets. If you open one of the corrupted PDFs in a text editor, I wonder if it's a bunch of HTML saying "access denied" - you could check. – James Mar 31 '22 at 15:35
  • In fact when I change the extension of the file saved with the code above, to html and open it in the browser I get the Gogle logo with this message "One account for all Google products", the same link used is allowing me to download the pdf file into my local machine, and I'm using chrome with the profile allowed to this google drive account connected. the html file has text box to input the google account, when I fill it, I get the pdf file downloaded ! To summurize, instead of saving the file to the server, I'm always getting a download link to the local machine ! – Kemal AL GAZZAH Mar 31 '22 at 15:43
  • It seems that saving the PDF requires adding some authentication, the question, is how to pass this authentication to this code ( Using client = New System.Net.WebClient() client.DownloadFile(url, tofile) End Using) – Kemal AL GAZZAH Mar 31 '22 at 15:52
  • Not so easy, unfortunately. Check https://stackoverflow.com/questions/8601302/c-sharp-webclient-login-to-accounts-google-com – James Mar 31 '22 at 16:06
  • Thank you, Do you think this solution https://stackoverflow.com/questions/64427559/how-to-convert-blob-url-to-a-byte-array-using-javascript-only can work in my case ? – Kemal AL GAZZAH Mar 31 '22 at 16:07
  • I have never built a c# app that logs into google, but I did write one that logs into another server which was kind of similar. I used the "cookie aware web client" approach that Rob B's answer talks about. I don't think the approach in the answer you linked is comparable to your existing code. – James Mar 31 '22 at 16:10

0 Answers0