Determine DateLastModified for a web base JPG Image via ASP or ASPNet

一曲冷凌霜 提交于 2019-12-13 04:41:22

问题


Using VBS in an ASP page or ASPNet page, I would like to determine the date when a remote web-based JPG file was created (or modified, etc). For example a webcam shot which was FTP-ed to the website. Thus, with the URL of the JPG, how can I get to the properties of that JPG.

In the code below I tried to retrieve the image file and save it into my site web, but I get an error on the "objADOStream.SaveToFile (strSave,2)" line which says that

"System.Runtime.InteropServices.COMException: Write to file failed.".

I know I have read/write permissions to that folder as I regularly create/delete .txt files there.

  • Can you comment on why I am not able to save this file?
  • Assuming I do get it saved will the original file properties be retained?
  • Or, maybe even better, is there an easier way to get this photo file information?

Here is the code that I cobbled together to retrieve and save the file

 dim strURL, strSave, objXMLHTTP, objADOStream, objFSO

 strURL = "http://www.somewhere.com/Photo.jpg"
 strSave = Server.MapPath("/xxx/photos/") & "photo.jpg"

 objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

 objXMLHTTP.open ("GET", strURL, false)
 objXMLHTTP.send()

 if err.number=0 then

if objXMLHTTP.readystate = 4 then

  If objXMLHTTP.Status = 200 Then

    objADOStream = CreateObject("ADODB.Stream")
    objADOStream.Open
    objADOStream.Type = 1 

    objADOStream.Write (objXMLHTTP.ResponseBody)
    objADOStream.Position = 0       

    objFSO = Createobject("Scripting.FileSystemObject")

    If objFSO.Fileexists(strSave) Then objFSO.DeleteFile (strSave)
    objFSO = Nothing

    objADOStream.SaveToFile (strSave,2)
    objADOStream.Close
    objADOStream = Nothing
  End If
end if
 end if
 objXMLHTTP = Nothing

Thanks...RDK


回答1:


If all you need is to know the last modification date of the file, instead of sending a GET request, send a HEAD request. In your code change GET with HEAD and, after send get

objXMLHTTP.getResponseHeader("Last-Modified") 

It is possible that the server don't send this information, so you have no way to know this data.



来源:https://stackoverflow.com/questions/20176324/determine-datelastmodified-for-a-web-base-jpg-image-via-asp-or-aspnet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!