Try our conversational search powered by Generative AI!

Caching Images after replace the images



I  programatically upload an image . I can see that image in the asset pane at the CMS admin .But when i browse the page , it always showing the previous image after replace the image

 my code is

if (userProfileImage != null)
 newImage  =   (ImageFile)contentRepository.Get(userProfileImage.ContentLink).CreateWritableClone();;



newImage = contentRepository.GetDefault(folder.ContentLink);
newImage.Name = userIfo.FirstName;


var byteArrayData = imageService.ToByteArray(image); ;

var blob = blobFactory.CreateBlob(newImage.BinaryDataContainer, extention);
using (var s = blob.OpenWrite())
var w = new StreamWriter(s);
w.BaseStream.Write(byteArrayData, 0, byteArrayData.Length);

newImage.BinaryData = blob;

var imageContentRef = contentRepository.Save(newImage, SaveAction.Publish, AccessLevel.NoAccess);

Thanks in advance

Feb 02, 2018 4:07

Hi, Jaanna,

Browser caches based on the URL, so when uploading a new image, you need to change the URL segment if you want hint the browser that the image has changed.

So, you could either name the image based on a date and then clear the URL segment (so that Epi automatically generates it for you) or you could just set the URL segment (but then you need to think of special characters yourself.

I do the first thing, but you will need to adjust this code to match your variable names:

var filename = string.Format("{0}{1}", DateTime.Now.ToString("yyyy-MM-dd_HHmm"), Path.GetExtension(file.FileName));

epiImageFile.Name = filename;
epiImageFile.RouteSegment = null;


Feb 02, 2018 14:19

@marija, you mean "renaming" the file?!

Feb 02, 2018 19:32

Yes, "renaming" the URL segment rather (as a consequence of renaming the Media and setting the segment to null).

// In case the URL for the image isn't important, which is seldom the case for images.

Feb 05, 2018 9:44
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.