How to link the image files on internet?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have so many photos storing on internet.

Now, I want to create an image object on Form or Report, so that users can
view the photos for each record. But it failed. In MS Access, Image Object is
not allowed to link the file from internet.

My access database will be used in many countries and not expected to
download the photos to any LAN server or PC.

Any other method to handle it?

Thanks & regards,
Eddy
 
Hi,

Eddy schreibselte:
I have so many photos storing on internet.

Now, I want to create an image object on Form or Report, so that
users can view the photos for each record. But it failed. In MS
Access, Image Object is not allowed to link the file from internet.

My access database will be used in many countries and not expected to
download the photos to any LAN server or PC.

Any other method to handle it?

There is no possibility to show pictures in a
form or in browser without downloading it to
local machine.

Acki
 
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
 
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
 
Back
Top