-
Jul 26th, 2018, 08:09 PM
#1
Thread Starter
Junior Member
[RESOLVED] Downloading File from Google Drive URL
Hi guys,
I've been looking for a way to download a google drive file using via its url. The code snippet below is what I used to download from a dropbox url and it works flawlessly.
Try
Dim wc As New WebClient
AddHandler wc.DownloadFileCompleted, AddressOf wc_DownloadCompleted
AddHandler wc.DownloadProgressChanged, AddressOf wc_ProgressChanged
Dim savefile As New SaveFileDialog
Dim fileurl As String = "https://www.dropbox.com/s/8pd5ovtjh70lylc/CMH%20Infosys.exe?dl=1"
Dim filelocation As String = InfosysPath & "Infosys\Updates\Infosys.exe"
If System.IO.File.Exists(filelocation) Then My.Computer.FileSystem.DeleteFile(filelocation)
wc.DownloadFileAsync(New Uri(fileurl), filelocation)
Catch ex As Exception
MsgBox("Download Failed")
Call LoadData()
End Try
I thought maybe if I plug in my google drive url then it should work but it doesn't. I've been looking for a solution online but no luck. Is there a different method of getting this done? I appreciate any help on this topic.
-
Jul 26th, 2018, 08:39 PM
#2
Re: Downloading File from Google Drive URL
Originally Posted by iantiu
I thought maybe if I plug in my google drive url then it should work but it doesn't.
"It doesn't work" is never an adequate explanation. Why actually DOES happen when you use that code? If you need to simplify things for testing, just call DownloadFile without all the other stuff and if it throws an exception, give us all the relevant information about that exception.
-
Jul 26th, 2018, 08:40 PM
#3
Re: Downloading File from Google Drive URL
By the way, if you're going to post code snippets then please use appropriate formatting tags for readability:
Code:
Try
Dim wc As New WebClient
AddHandler wc.DownloadFileCompleted, AddressOf wc_DownloadCompleted
AddHandler wc.DownloadProgressChanged, AddressOf wc_ProgressChanged
Dim savefile As New SaveFileDialog
Dim fileurl As String = "https://www.dropbox.com/s/8pd5ovtjh70lylc/CMH%20Infosys.exe?dl=1"
Dim filelocation As String = InfosysPath & "Infosys\Updates\Infosys.exe"
If System.IO.File.Exists(filelocation) Then My.Computer.FileSystem.DeleteFile(filelocation)
wc.DownloadFileAsync(New Uri(fileurl), filelocation)
Catch ex As Exception
MsgBox("Download Failed")
Call LoadData()
End Try
-
Jul 26th, 2018, 08:43 PM
#4
Re: Downloading File from Google Drive URL
Also, if an exception is thrown during the download then the exception handler you have shown there isn't going to catch it, because it is thrown on a secondary thread. You would need to examine the 'e.Error' property in the DownloadFileCompleted event handler for that. There's no indication of whether you're doing that or not in what you've posted.
-
Jul 27th, 2018, 05:23 AM
#5
Addicted Member
Re: Downloading File from Google Drive URL
Originally Posted by iantiu
Hi guys,
I've been looking for a way to download a google drive file using via its url.
You didn't show us the URL you're using, if it is the one that you get from Google Drive's "Get sharable link" then it won't work because it's not a direct link.
The sharable link would look like this:
https://drive.google.com/open?id=xxxxxxxx
To get the direct link, use this link:
https://docs.google.com/uc?export=download&id=xxxxxxxx
Replace the Xs with your file id
Hope that helps
-
Jul 27th, 2018, 06:50 AM
#6
Thread Starter
Junior Member
Re: Downloading File from Google Drive URL
Originally Posted by jmcilhinney
"It doesn't work" is never an adequate explanation. Why actually DOES happen when you use that code? If you need to simplify things for testing, just call DownloadFile without all the other stuff and if it throws an exception, give us all the relevant information about that exception.
First of all, I appreciate your input. Sorry about the vagueness. What I run the code with a google drive url, the file appears to download but when I run the file, the file is "corrupt" No exception is thrown.
I am new to google drive and I've been using dropbox a while now. I never realized there are two different urls for google drive. Apparently, I've been using the open url. This one that cPubis suggested worked for me:
https://drive.google.com/uc?export=d...HLsOaH-QUZ-vag
I know the solution will be quite simple, I just can't figure out what I did wrong. Thank you for your responses jmcilhinney and cPubis. Have a great day!
-
Jul 27th, 2018, 06:56 AM
#7
Re: Downloading File from Google Drive URL
Originally Posted by iantiu
This one that cPubis suggested worked for me:
Excellent. Be sure to use the Thread Tools menu to mark this thread Resolved.
-
Jul 27th, 2018, 08:07 AM
#8
Addicted Member
Re: Downloading File from Google Drive URL
Originally Posted by iantiu
I never realized there are two different urls for google drive.
It's not your fault. The direct link trick is not documented on any of Google's websites. It's kind of a hack, a workaround, it's leaching and Google will hate it if you use it intensively. Be wise using it or else Google will block it for all of us. Have a nice day.
-
Jul 27th, 2018, 08:08 AM
#9
Addicted Member
Re: Downloading File from Google Drive URL
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|