Click to See Complete Forum and Search --> : Best way to download file
Peon
Nov 3rd, 2008, 04:30 AM
I am using Inet but it seems it fails to download file which has some redirects
for example
file : http://youtube.com/get_video?video_id=fCAkFMVdKUg&t=OEgsToPDskIkcKTux4cwXazKqj_xj5Yf
it has some redirects so how to download that kind of files using vb?
Hack
Nov 3rd, 2008, 07:09 AM
"Seems it fails" - what does that mean?
Peon
Nov 3rd, 2008, 07:17 AM
"Seems it fails" - what does that mean?
I meant that it doesn't accomplish the task or may be I am using it wrong.
Following is code
Inet1.Execute Trim(Link), "GET"
Do While Inet1.StillExecuting
DoEvents
Loop
size = Inet1.GetHeader("Content-Length")
and size is returned ZERO... so I think its because of redirects.
and Link variable contains the url
http://youtube.com/get_video?video_id=fCAkFMVdKUg&t=OEgsToPDskIkcKTux4cwXazKqj_xj5Yf
jmsrickland
Nov 3rd, 2008, 08:44 AM
There are quite a few threads in here and alot of them are very recent about doing what you are trying to do.
Try using another link. It appears that the page no longer exists.
Peon
Nov 3rd, 2008, 11:33 AM
There are quite a few threads in here and alot of them are very recent about doing what you are trying to do.
I have used search function but none of the address come up with the redirects issue solution.. I give it another try.
Try using another link. It appears that the page no longer exists.
for me that link is working and offering get_video page to download which is infact a flv file.
jmsrickland
Nov 3rd, 2008, 11:38 AM
When I click on that link I get this:
The page does not exist
The page you are looking for has been removed.
Peon
Nov 3rd, 2008, 12:23 PM
When I click on that link I get this:
The page does not exist
The page you are looking for has been removed.
Well, It happens because rotate the parameters every few hours. Anyhow.. I have changed the urls now they open.
isnoend07
Nov 3rd, 2008, 05:58 PM
Add reference to WinHTTP.dll in systems32. (Browse to it, if Microsoft WinHTTP services doesn't show on the references list.)
Note this simple example doesn't do anything fancy, just dumps the downloaded bytes to disk.
OnResponseStart when you can safely access the headers.
OnResponseDataAvailable which returns a byte array of downloaded data for each chunk.
OnResponseEnd which ends the download.
Option Explicit
Private WithEvents http As WinHttpRequest
Private mContentLength As Long
Private mProgress As Long
Private Sub Command1_Click()
' Create the WinHTTPRequest ActiveX Object.
Set http = New WinHttpRequest
' Open an HTTP connection.
http.open "GET", "http://home.in.tum.de/~paula/mpeg/wg_gdo_1.mpg", True 'True means asynch.
' Send the HTTP Request.
http.send
End Sub
Private Sub http_OnResponseDataAvailable(Data() As Byte)
mProgress = mProgress + UBound(Data) + 1
ProgressBar1.Value = mProgress
Put #1, , Data
End Sub
Private Sub http_OnResponseFinished()
Close #1
MsgBox "done"
End Sub
Private Sub http_OnResponseStart(ByVal Status As Long, ByVal ContentType As String)
Text1.Text = http.getAllResponseHeaders()
mProgress = 0
mContentLength = CLng(http.getResponseHeader("Content-Length"))
ProgressBar1.Max = mContentLength
Open "C:\twg_gdo_1.mpg" For Binary As #1
End Sub
Peon
Nov 5th, 2008, 08:54 AM
Add reference to WinHTTP.dll in systems32. (Browse to it, if Microsoft WinHTTP services doesn't show on the references list.)
Note this simple example doesn't do anything fancy, just dumps the downloaded bytes to disk.
OnResponseStart when you can safely access the headers.
OnResponseDataAvailable which returns a byte array of downloaded data for each chunk.
OnResponseEnd which ends the download.
Option Explicit
Private WithEvents http As WinHttpRequest
Private mContentLength As Long
Private mProgress As Long
Private Sub Command1_Click()
' Create the WinHTTPRequest ActiveX Object.
Set http = New WinHttpRequest
' Open an HTTP connection.
http.open "GET", "http://home.in.tum.de/~paula/mpeg/wg_gdo_1.mpg", True 'True means asynch.
' Send the HTTP Request.
http.send
End Sub
Private Sub http_OnResponseDataAvailable(Data() As Byte)
mProgress = mProgress + UBound(Data) + 1
ProgressBar1.Value = mProgress
Put #1, , Data
End Sub
Private Sub http_OnResponseFinished()
Close #1
MsgBox "done"
End Sub
Private Sub http_OnResponseStart(ByVal Status As Long, ByVal ContentType As String)
Text1.Text = http.getAllResponseHeaders()
mProgress = 0
mContentLength = CLng(http.getResponseHeader("Content-Length"))
ProgressBar1.Max = mContentLength
Open "C:\twg_gdo_1.mpg" For Binary As #1
End Sub
It worked superb...
just a new thought in my mind..
Is it possible to download only specific part of file?
Suppose file size is 1024 KB.
First file is downloaded 1KB to 100KB.
Then resuming it from 101KB to 1024KB.
I have achieved this functionality in php but still not successful with doing this in vb.
isnoend07
Nov 5th, 2008, 09:59 AM
It worked superb...
just a new thought in my mind..
Is it possible to download only specific part of file?
Suppose file size is 1024 KB.
First file is downloaded 1KB to 100KB.
Then resuming it from 101KB to 1024KB.
I have achieved this functionality in php but still not successful with doing this in vb.
Seems to me you could stop it at a certain byte. Don't know about resuming at the next byte. You may want to post this as a new question.
jmsrickland
Nov 5th, 2008, 02:09 PM
Is there something wrong with that code? I use it and everything I download is missing the sound from the file. I downloaded that example mpg (exactly as shown in the post) and I get the video but no sound. So I changed the URL to something else (a You Tube video) and also got the video but again no sound. I know it is not my sound card cause I can play music on my PC and it is audiable.
isnoend07
Nov 5th, 2008, 03:26 PM
Is there something wrong with that code? I use it and everything I download is missing the sound from the file. I downloaded that example mpg (exactly as shown in the post) and I get the video but no sound. So I changed the URL to something else (a You Tube video) and also got the video but again no sound. I know it is not my sound card cause I can play music on my PC and it is audiable.
Been using the code for a year. I use it like this:
It downloads a real small text file that holds a version number. This version number is compared to the users exe version number and if its higher then they can then download the exe. The exe is 14980kb and i gotta say it has always worked. Here is a working example:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=69060, it also uses WinHttpRequest
Don't know what could be wrong other than downloading the file with your browser to make sure it's valid.
jmsrickland
Nov 6th, 2008, 12:09 AM
I just don't think the file has sound to it.
What does that link do? I don't see where it has anything to do with the code and link you posted.
isnoend07
Nov 6th, 2008, 12:29 AM
I just don't think the file has sound to it.
What does that link do? I don't see where it has anything to do with the code and link you posted.
It downloads files. I have posted a valid wav file that works on my website for you to test here: http://roofgenius.com/wahoo.wav
Hope this helps
jmsrickland
Nov 6th, 2008, 10:48 AM
It returns Page Cannot Be Found. I even tried http://www.roofgenius.com/wahoo.wav
The URL http://www.roofgenius.com seems to be OK; so it must be the wahoo.wav that it can't find.
isnoend07
Nov 6th, 2008, 11:03 AM
It returns Page Cannot Be Found. I even tried http://www.roofgenius.com/wahoo.wav
The URL http://www.roofgenius.com seems to be OK; so it must be the wahoo.wav that it can't find.
Whoops
It's Whoo.wav
sorry
jmsrickland
Nov 6th, 2008, 01:18 PM
OK, now using the code you posted in #8 and the following statement:
http.Open "GET", "http://www.roofgenius.com/Whoo.wav", True
It downloads the file and there is sound. But when I download this....
http.Open "GET", "http://home.in.tum.de/~paula/mpeg/wg_gdo_1.mpg
I get the video but no sound.
So, I am assuming the file does not contain sound in it.
isnoend07
Nov 6th, 2008, 01:25 PM
OK, now using the code you posted in #8 and the following statement:
http.Open "GET", "http://www.roofgenius.com/Whoo.wav", True
It downloads the file and there is sound. But when I download this....
http.Open "GET", "http://home.in.tum.de/~paula/mpeg/wg_gdo_1.mpg
I get the video but no sound.
So, I am assuming the file does not contain sound in it.
I downloaded the file in your link with my browser and it does not contain sound
jmsrickland
Nov 6th, 2008, 02:40 PM
I downloaded the file in your link with my browser and it does not contain sound
Not my link; it was the link in your code from your post #8
isnoend07
Nov 6th, 2008, 02:53 PM
I downloaded the file in your link with my browser and it does not contain sound
Not my link; it was the link in your code from your post #8
That file was just an old example, don't know if it ever existed. Think I copied it from somewhere I expected you to supply your own file
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.