Re: How to link the image files on internet?
- From: "Eddy" <Eddy@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 22 Jul 2005 02:20:01 -0700
Thanks a lot!
But, sometimes, when the image is not available on the internet, a "404 file
not found" html file will be download and saved as JPG. Error occur when
displaying such incorrect JPG.
How can I know the downloaded file is JPG, but not the "404" html file?
Regards,
Eddy
"Jörg Ackermann" wrote:
> Hi,
>
> Jörg Ackermann:
>
> > There is no possibility to show pictures in a
> > form or in browser without downloading it to
> > local machine.
>
> A short way should be to use MSXML:
>
> ---------Module basDownload--------------------
> Option Compare Database
> Option Explicit
>
> Private Declare Function GetTempPath Lib "kernel32" _
> Alias "GetTempPathA" ( _
> ByVal nBufferLength As Long, _
> ByVal lpBuffer As String) _
> As Long
>
> Private Declare Function GetTempFileName Lib "kernel32" _
> Alias "GetTempFileNameA" ( _
> ByVal lpszPath As String, _
> ByVal lpPrefixString As String, _
> ByVal wUnique As Long, _
> ByVal lpTempFileName As String) _
> As Long
>
> Private Const MAX_PATH = 255
>
> Public Function DownloadPicture(ByVal strURL As String) As String
>
> Dim xmlhttp As Object
> Dim oStream As Object
> Dim strTmp As String
>
> On Error GoTo Err_DownloadPicture
>
> Set xmlhttp = CreateObject("Msxml2.XMLHTTP")
> With xmlhttp
> .Open "GET", strURL, False
> .setRequestHeader "CONTENT-TYPE", "image/jpeg"
> .send
> Do Until .readyState = 4
> DoEvents
> Loop
> End With
>
> strTmp = GetTmpFileName(Right(strURL, 3))
>
> Set oStream = CreateObject("ADODB.Stream")
> With oStream
> .Mode = 3 'adModeReadWrite
> '.Charset = "iso-8859-1"
> .Type = 1 'adTypeBinary
> .Open
> .Write (xmlhttp.responseBody)
> .SaveToFile strTmp
> End With
>
> Set oStream = Nothing
> Set xmlhttp = Nothing
>
> If Dir(strTmp) <> "" Then
> If FileLen(strTmp) > 0 Then
> DownloadPicture = strTmp
> End If
> End If
>
> Exit_DownloadPicture:
> Exit Function
> Err_DownloadPicture:
> MsgBox Err.Description
> Resume Exit_DownloadPicture
> End Function
>
> Private Function GetTmpFileName(sSuffix As String) As String
>
> Dim strPath As String, _
> strFolder As String
> Dim lngResult As Long
>
> strFolder = String(MAX_PATH, 0)
> lngResult = GetTempPath(MAX_PATH, strFolder)
> strFolder = Left$(strFolder, InStr(1, strFolder, Chr$(0)) - 1)
>
> strPath = String(MAX_PATH, 0)
> lngResult = GetTempFileName(strFolder, "PIC", 0, strPath)
> strPath = Left$(strPath, InStr(1, strPath, Chr$(0)) - 1)
> GetTmpFileName = Replace(strPath, ".tmp", "." & sSuffix)
>
> End Function
>
> ---------Module basDownload--------------------
>
> In a form with a textbox(txtURL), a picturebox(picFoto) and a
> comandbutton(cmdGo) you can do:
>
> Private Sub cmdGo_Click()
> Me!picFoto.Picture = DownloadPicture(Me!txtURL)
> End Sub
>
> Acki
>
>
.
- References:
- How to link the image files on internet?
- From: Eddy
- Re: How to link the image files on internet?
- From: Jörg Ackermann
- Re: How to link the image files on internet?
- From: Jörg Ackermann
- How to link the image files on internet?
- Prev by Date: Re: Profile MS Access
- Next by Date: Re: Moving ADO routine back to DAO
- Previous by thread: Re: How to link the image files on internet?
- Next by thread: suppress error message in Access VB
- Index(es):
Relevant Pages
|