November Happy Hour will be moved to Thursday December 5th.

Where should I store uploaded image files in a load balanced environment?

Vote:
 

Hi!

I'm working on an episerver site where visitors can create personal profiles. They can also upload personal image files that will be displayed on their profile page. I'm not sure where the best place to store these files are? If I store them in a folder under the site, how can that folder be shared between the different deployments in a load balanced environment? I don't want to store them as media in the content repository because I don't want them to be accessible in the file manager, or can they be hidden?

#150263
Jun 15, 2016 9:22
Vote:
 

Uploading files

If you upload files I strongly recommend that you don't store them in the web root folder. Nothing should be added or changed in the web folder between two deploys.

There are some ways hat you can store files, for example using NAS or some technique that would mirror folders and files between servers.

The most simplest way I would say is to create a folder on a separate file server or on one of your load balanced servers.

Make this folder accessible on your network as a shared folder, for example \\servername\webfiles and make sure that the user running the IIS application pools have access to these.

When it comes to displaying these images you could either create a proxy that reads the image from the file share and outputs it to the response stream to the visitor, or try with a Virtual Folder in your IIS website. Deciding with option would be based on how you manage uploaded images.

Files as content 

If you create a ContentFolder as a child under ContentReference.RootPage, they won't be visible in the media tab of the Asset Pane.

#150273
Jun 15, 2016 11:46
Vote:
 

Thanks for your answer Alf!

I choosed to store the files in the repository but as you suggested I stored them under a page instead of in global assets. This works pretty good except when I use the Delete method on the repository to delete an image content, then I get an exception that the content does not extend the PageData class. Using the MoveToWastebasket however works fine, but I would prefer to use the Delete method.

#150355
Jun 16, 2016 15:56
Vote:
 

I think it works better if you programmatically creates a content folder under the root page and creates your files as children to that folder. Could that help?

#150356
Jun 16, 2016 16:01
Vote:
 

No, still the same error.

This is what I did (The "ProfileImages" folder is created in an initialization module):

...
var
 imageFolder = contentRepository.GetChildren<ContentFolder>(ContentReference.RootPage).FirstOrDefault(c => c.Name.Equals("ProfileImages")); if (imageFolder != null) { var file = contentRepository.GetDefault<ImageFile>(imageFolder.ContentLink); file.Name = profile.User + Guid.NewGuid()+ Path.GetExtension(image.FileName); var blob = blobFactory.CreateBlob(file.BinaryDataContainer, Path.GetExtension(image.FileName)); blob.Write(image.InputStream); file.BinaryData = blob; profile.ImageContentReference = contentRepository.Save(file, SaveAction.Publish, AccessLevel.NoAccess); }

Later on the following Delete fails with the this exception message {"Content with id '3536' is of type 'Castle.Proxies.ImageFileProxy' which does not inherit required type 'EPiServer.Core.PageData'"}
contentRepository.Delete(new ContentReference(profile.ImageContentReference),true,AccessLevel.NoAccess);
#150363
Jun 16, 2016 17:10
Vote:
 

Weird. Could you give more details from the callstack?

Also I don't think it's necesarry that you do new ContentReference(profile.ImageContentReference) if ImageContentReference already is a ContentReference.
Guess that would not solve your problem but give a simpler code :)

#150365
Edited, Jun 16, 2016 17:17
Vote:
 

The "new ContentReference" was a typo, sorry about that.

I also found the problem, there was an eventlistener that I was unaware of which was causing the issue.

Thanks for your help!!

#150366
Jun 16, 2016 17:26
Vote:
 

Great! Happy to help!

#150367
Jun 16, 2016 17:28
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.