Friday 12 August 2016

Storing Sitecore Media in the Shared File System Folder

Leave a Comment
In this blog post, I am going to explain how to store Sitecore media items in the Shared File System Folder. By default, Sitecore stores media assets in database but this behaviour can be customized so that Sitecore can store media assets into File System. I recommend checking Storing Sitecore Media in the Database vs. the File System post by Sitecore MVP Mark Ursino for pros/cons of both techniques.

Below steps are required to store Sitecore media items in the Shared File System Folder:
  1. Open Sitecore.config ( Sitecore 8.1) or web.config (Sitecore 8.0) file and set the Media.UploadAsFiles setting to true:
    <setting name="Media.UploadAsFiles" value="true">
  2. Open IIS and navigate to website node. Right click the website node and click the Add Virtual Directory.
  3. In the Add Virtual Directory dialog box, specify the following information:
    Alias: Type a name for the virtual directory. Choose a short and meaningful name. This alias name will be used at Step 4.
    Physical Path: Type Shared File System Folder path.

    Click the Connect as button and provide credentials to connect to Shared File System Folder. Make sure the user account is having write access to Shared File System Folder else you will get into authorization issues.


    Click on Test Settings button to verify the connection.

  4. Open Sitecore.config ( Sitecore 8.1) or web.config (Sitecore 8.0) file and change the value of Media.FileFolder setting to alias name of virtual directory.
    <setting name="Media.FileFolder" value="/SharedMedia">
  5. Recycle application pool.

Troubleshooting:

You might see below exception in log file:
Exception: System.UnauthorizedAccessException Message: Access to the path '\\Network-26\SharedMedia\1\C\C' is denied. Source: mscorlib at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost) at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost) at Sitecore.Resources.Media.MediaData.SetFileStream(MediaStream mediaStream) at Sitecore.Resources.Media.Media.SetStream(MediaStream mediaStream) at Sitecore.Resources.Media.MediaCreator.AttachStreamToMediaItem(Stream stream, String itemPath, String fileName, MediaCreatorOptions options) at Sitecore.Resources.Media.MediaCreator.CreateFromStream(Stream stream, String filePath, MediaCreatorOptions options) at Sitecore.Resources.Media.MediaUploader.UploadToDatabase(List`1 list) at Sitecore.Resources.Media.MediaUploader.Upload() at Sitecore.Pipelines.Upload.Save.Process(UploadArgs args)
To resolve above issue; make sure the user account (used in Step 3) is having write access to Shared File System Folder. Comments and suggestions are most welcome. Happy coding!

0 comments :

Post a Comment