![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Determine a download's file-name from http request? Below is a script that downloads a binary file over http. What I need is a way of obtaining the file name returned by a URL request that is processed on the server side. eg. "http://www.downloads.com/files?id=abcdef12345" may return "archive.zip" Can the XMLHTTP object reveal the file name "archive.zip" to me? -----Code------ Private Sub FetchBinaryFile(FileURL, LocalFile) Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP") objXMLHTTP.open "GET", FileURL, false objXMLHTTP.send() If objXMLHTTP.Status = 200 Then Set objADOStream = CreateObject("ADODB.Stream") objADOStream.Open objADOStream.Type = 1 'adTypeBinary objADOStream.Write objXMLHTTP.ResponseBody objADOStream.Position = 0 'Set the stream position to the start Set objFSO = Createobject("Scripting.FileSystemObject") If objFSO.FileExists(LocalFile) Then objFSO.DeleteFile LocalFile Set objFSO = Nothing objADOStream.SaveToFile LocalFile objADOStream.Close Set objADOStream = Nothing End if Set objXMLHTTP = Nothing End Sub -----Code------ |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Determine a download's file-name from http request? Try looking into objXMLHTTP.getAllResponseHeaders() From there you may be able to parse out the suggested filename using getResponseHeader("headername"). Tim "ShayneH" <Shayne.Husson@xxxxxx> wrote in message news:a243b8a3-f9f0-4088-95ef-0dee9b261146@xxxxxx Quote: > Below is a script that downloads a binary file over http. > What I need is a way of obtaining the file name returned by a URL > request that is processed on the server side. > eg. "http://www.downloads.com/files?id=abcdef12345" may return > "archive.zip" > Can the XMLHTTP object reveal the file name "archive.zip" to me? > > -----Code------ > > Private Sub FetchBinaryFile(FileURL, LocalFile) > > Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP") > > objXMLHTTP.open "GET", FileURL, false > objXMLHTTP.send() > If objXMLHTTP.Status = 200 Then > Set objADOStream = CreateObject("ADODB.Stream") > objADOStream.Open > objADOStream.Type = 1 'adTypeBinary > objADOStream.Write objXMLHTTP.ResponseBody > objADOStream.Position = 0 'Set the stream position to the start > > Set objFSO = Createobject("Scripting.FileSystemObject") > If objFSO.FileExists(LocalFile) Then objFSO.DeleteFile LocalFile > Set objFSO = Nothing > > objADOStream.SaveToFile LocalFile > objADOStream.Close > Set objADOStream = Nothing > End if > Set objXMLHTTP = Nothing > End Sub > > -----Code------ |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Determine a download's file-name from http request? "Tim Williams" <timjwilliams at gmail dot com> wrote in message news:umhM4$JEJHA.4744@xxxxxx Quote: > Try looking into > > objXMLHTTP.getAllResponseHeaders() > > From there you may be able to parse out the suggested filename using > getResponseHeader("headername"). > It will contain filename="archive.zip" and may also contain the attachment keyword. Hence it still needs parsing:- sFileName = GetFileName(objXMLHTTP.getResponseHeader("Content-Disposition")) Function GetFileName(rsHeader) Dim rgx : Set rgx = New RegExp rgx.Pattern = "filename=(?:""([^""]+)""|([^;]+);?)" rgx.IgnoreCase = True GetFileName = "Unknown.dat" Dim oMatch For Each oMatch in rgx.Execute(rsHeader) GetFileName = oMatch.SubMatches(0) If GetFileName = "" Then GetFileName = oMatch.SubMatches(1) Exit For Next End Function -- Anthony Jones - MVP ASP/ASP.NET |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| HTTP error 400, bad request (invalid verb) | Vista mail | |||
| HTTP 400 Bad Request | Vista General | |||
| 3 second lag when making http request to localhost | Vista networking & sharing | |||
| Http request problem | PowerShell | |||
| http request and host header | PowerShell | |||