Avatar image bugs when deploy mojoPortal in virtual directory under website

This is the place to report bugs and get support. When posting in this forum, please always provide as much detail as possible.

Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum, do not report it as a bug.

This is the place to report bugs and get support

When posting in this forum, please try to provide as many relevant details as possible. Particularly the following:

  • What operating system were you running when the bug appeared?
  • What database platform is your site using?
  • What version of mojoPortal are you running?
  • What version of .NET do you use?
  • What steps are necessary to reproduce the issue? Compare expected results vs actual results.
Please do not report problems with a custom build or custom code in this forum. If you are producing your own build from the source code and have problems or questions, ask in the developer forum.
This thread is closed to new posts. You must sign in to post in the forums.
1/31/2012 8:54:20 PM
Gravatar
Total Posts 6

Avatar image bugs when deploy mojoPortal in virtual directory under website

Hi Joe,

Would like to report 2 bugs when the portal is deployed in virtual directory e.g. localhost/mojoportal:

1) Image cropping does not work when user uploads/changes avatar.

Reason

The bug is inside ImageCropper.ascx.cs.

The image path would become something like "/mojoportal~/Data/Sites/1/useravatars/user1.jpg" ("/mojoportal" is the application context).

The solution is to remove the "~" from the string.

Original Code

 private void PopulateControls()
{

if (!sourceExists)
{
pnlCrop.Visible = false;

}
else
{

imgToCrop.ImageUrl = Page.ResolveUrl(fileSystem.FileBaseUrl + sourceImagePath);
}

if (targetExists)
{
pnlCropped.Visible = true;
imgCropped.ImageUrl = Page.ResolveUrl(fileSystem.FileBaseUrl +  resultImagePath + "?g=" + Guid.NewGuid().ToString()); //prevent caching with a guid
}
else
{
pnlCropped.Visible = false;
}
}

Fix:

 private void PopulateControls()
{

if (!sourceExists)
{
pnlCrop.Visible = false;

}
else
{
if (sourceImagePath.StartsWith("~"))
{
   imgToCrop.ImageUrl = Page.ResolveUrl(fileSystem.FileBaseUrl + sourceImagePath.Substring(1) );
}
else
imgToCrop.ImageUrl = Page.ResolveUrl(fileSystem.FileBaseUrl + sourceImagePath);
}

if (targetExists)
{
pnlCropped.Visible = true;

if (resultImagePath.StartsWith("~"))
{
imgCropped.ImageUrl = Page.ResolveUrl(fileSystem.FileBaseUrl + resultImagePath.Substring(1) + "?g=" + Guid.NewGuid().ToString()); //prevent caching with a guid
}
else
imgCropped.ImageUrl = Page.ResolveUrl(fileSystem.FileBaseUrl +  resultImagePath + "?g=" + Guid.NewGuid().ToString()); //prevent caching with a guid
}
else
{
pnlCropped.Visible = false;
}

log.Info("  imgToCrop.ImageUrl : " + imgToCrop.ImageUrl );
}

2) Avatar image does not refresh in user profile after uploading a new image.

Reason

The image is cached in the browser.

Original Code in UserProfile.aspx.cs

 if ((!allowGravatars)&&(!disableAvatars))
{
if (siteUser.AvatarUrl.Length > 0)
{
imgAvatar.Src = avatarPath + siteUser.AvatarUrl  ;
}
.........

Fix

 if ((!allowGravatars)&&(!disableAvatars))
{
if (siteUser.AvatarUrl.Length > 0)
{
imgAvatar.Src = avatarPath + siteUser.AvatarUrl + "?g=" + Guid.NewGuid().ToString() ; // prevent caching with a gguid
}

...............................

 

-Hung

2/1/2012 10:25:26 AM
Gravatar
Total Posts 18439

Re: Avatar image bugs when deploy mojoPortal in virtual directory under website

Hi Hung,

I agree with your changes in ImageCropper but not in user profile. I don't think we want to prevent caching of the image by the web browser on every request. I will look into another solution to solve the cache problem, parhaps a way to rename the file after it is updated.

Best,

Joe

2/1/2012 1:17:42 PM
Gravatar
Total Posts 18439

Re: Avatar image bugs when deploy mojoPortal in virtual directory under website

Hi Hung,

This is now fixed in the source code repository. I made a change to rename the avater file after it is updated, so that should solve the browser cache problem.

Thanks,

Joe

2/1/2012 7:53:37 PM
Gravatar
Total Posts 6

Re: Avatar image bugs when deploy mojoPortal in virtual directory under website

Thanks Joe. I was not thinking about the timestamp and caching.

Just to share, in Liferay portal, they actually stores the last updated timestamps for all of their images (including profile, image gallery, CMS , etc) in the database. Then the url would be something like "/image?id=xxxx&lastupdatedtimestamp=xxxx" .

They are also doing it for other uploaded files (e.g. javascript/css files after minifying & combining )  in the CMS to prevent browser caching. In addition, there is a filter which intercepts all the requests and return the last cached versions (which is based on EhCache) .

Perhaps, this idea might be useful in future if we need to :)

- Hung

You must sign in to post in the forums. This thread is closed to new posts.