image caching problem

Discussion in 'ASP.NET / ASP.NET Core' started by thewebschoo, Oct 26, 2006.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. my application requires a user to upload a jpg file which i store in a database and then write to a file on the server so that i can use the imageurl property of an image controll to display the uploaded image as feedback to the client browser....what i have noticed now is that for a browser session the first image uploaded is the one that would persist even if a diffrent one is uploaded[although the name giving to the file is the same for every browser session [i used the sessionid as the name of the file.jpg]
    but even when the content of the file has changed i keep having the first picture displayed until i initiate another session ]
    please can you help on how to turn of this catching option..




    Post Edited By Moderator (Joel Thoms) : 10/27/2006 5:46:39 PM GMT
     
  2. Does the new image replace the old one on the file system?Also where in your codeyou pull the image for the user?

    Vikram

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. This is going to be complex to debug unless you can provide some sample code we can play around with.

    The browser should perform a HEAD query on the file to see if it has changed and only request the object if it has.

    I'm guessing you are serving the image off disk via http and not proxying it through a script of some kind?

    Do you want the image to be cached except for when it changes, or do you always want caching disabled? If you never want to cache you could do something like...

    Image1.ImageUrl = "P" & Session.SessionID & ".jpg?x=" & randomStuff


    Also clear your browsers cache. Check to find out if the browser is caching the image or if the web server is caching the image.


    Joel Thoms
    DiscountASP.NET
    http://www.DiscountASP.NET
     
  4. I HAVE CONFIRMED THAT THE IMAGE IS INDEED REPLACED WITH A NEW ONE . I COPIED THE FILE FROM THE SERVER TO MY DESK TOP TO ACHIEVE THIS.





    BELOW IS THE CODE IMPLEMENTATION FOR THE IMAGE UPDATE PROCESS





    If File1.PostedFile.FileName.EndsWith("JPG") = False And File1.PostedFile.FileName.EndsWith("JPEG") = False Then
    If File1.PostedFile.FileName.EndsWith("jpg") = False And File1.PostedFile.FileName.EndsWith("jpeg") = False Then
    Me.lb_error_msg.Visible = True
    Me.lb_error_msg.Text = "Only JPEG (.jpg) file formart is allowed"
    Return -1
    End If


    End If
    If File1.PostedFile.ContentLength <= 6 Then
    Me.lb_error_msg.Visible = True
    Me.lb_error_msg.Text = "File Not Included In Upload"
    Return -1
    End If
    If File1.PostedFile.ContentLength > 60000 Then
    Me.lb_error_msg.Visible = True
    Me.lb_error_msg.Text = "Maximum Size of Image Is 60 Kilo Bytes the size uploaded is " &amp; Math.Ceiling(File1.PostedFile.ContentLength / 1000).ToString("#,##0") &amp; " Kilobytes"
    Return -1
    End If


    'save file
    File1.PostedFile.InputStream.Read(lbyte, 0, (File1.PostedFile.InputStream.Length - 1))


    [THIS IS THE ROUTINE THAT WRITES THE IMAGE TO THE DATABASE]


    If lcls_army_buis_rule.Save_Image(lbyte, Session("pin"), ls_error_msg) = -1 Then
    Me.lb_error_msg.Visible = True
    Me.lb_error_msg.Text = ls_error_msg
    Return -1
    End If


    [THIS IS WHERE THE FILEPATH IS ESTABLISHED]
    ls_file_name = Server.MapPath("P" &amp; Session.SessionID &amp; ".jpg")


    [THIS IS THE ROUTINE THAT WRITES THE FILE TO DISK]
    If lcls_army_buis_rule.Write_File_To_disk(ls_file_name, Session("pin"), ls_error_msg) = -1 Then
    Me.lb_error_msg.Visible = True
    Me.lb_error_msg.Text = ls_error_msg
    Return -1
    End If


    [THIS IS THE DYNAMIC ALLOCATION OF THE FILE NAME NOT PATH AND REMEBER THIS ROUTINE WORKS IF IT IS THE FIRST TIME THE IMAGE IS UPLOADED]
    Image1.ImageUrl = "P" &amp; Session.SessionID &amp; ".jpg"
     
  5. thanks for the help i now say another way of displaying the image from a refrence i saw from this forum

    Retrieving Images Stored in SQL Server
    at
    http://authors.aspalliance.com
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page