Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anthony Feudale 5 posts 96 karma points
    Aug 01, 2016 @ 14:23
    Anthony Feudale
    0

    Overriding IFileSystem

    Hi all. I'm currently trying to make my Umbraco media use a database to populate. In order to do so I believe I need to implement IFileSystem in a custom class.

    I'm hazy on how to make this work however as the exact workings of the default PhysicalFileSystem are very unclear. Could somebody give me some guidance on how to proceed?

    I've looked at an Azure Blob System which does this as an example but it doesn't seem very illuminating.

  • Sebastiaan Janssen 5061 posts 15523 karma points MVP admin hq
    Aug 02, 2016 @ 15:35
    Sebastiaan Janssen
    100

    This is how PhysicalFileSystem works, exactly:

    https://github.com/umbraco/Umbraco-CMS/blob/75c2b07ad3a093b5b65b6ebd45697687c062f62a/src/Umbraco.Core/IO/PhysicalFileSystem.cs

    If you want to implement your own, you'll need a class that inherits from IFileSystem and then you implement all the methods.

    using System;
    using System.Collections.Generic;
    using System.IO;
    using Umbraco.Core.IO;
    
    namespace MyNamespace 
    {
        internal class MyFileSystem : IFileSystem
        {
            public IEnumerable<string> GetDirectories(string path) { // implement me }
    
            public void DeleteDirectory(string path) { // implement me }
    
            public void DeleteDirectory(string path, bool recursive) { // implement me }
    
            public bool DirectoryExists(string path) { // implement me }
    
            public void AddFile(string path, Stream stream) { // implement me }
    
            public void AddFile(string path, Stream stream, bool overrideIfExists) { // implement me }
    
            public IEnumerable<string> GetFiles(string path) { // implement me }
    
            public IEnumerable<string> GetFiles(string path, string filter) { // implement me }
    
            public Stream OpenFile(string path) { // implement me }
    
            public void DeleteFile(string path) { // implement me }
    
            public bool FileExists(string path) { // implement me }
    
            public string GetRelativePath(string fullPathOrUrl) { // implement me }
    
            public string GetFullPath(string path) { // implement me }
    
            public string GetUrl(string path) { // implement me }
    
            public DateTimeOffset GetLastModified(string path) { // implement me }
    
            public DateTimeOffset GetCreated(string path) { // implement me }
        }
    }
    
  • Anthony Feudale 5 posts 96 karma points
    Aug 10, 2016 @ 20:26
    Anthony Feudale
    0

    Thanks for the info. I realized after quite a bit of slogging that my issue was with the FileSystemProvider.config file. I hadn't realized that the second entry of the <Provider> tag referred to the assembly for the custom class which inherited from IFileSystem I made to replace PhysicalFileSystem.

    Original Code

     <Provider alias="media" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
    <Parameters>
      <add key="virtualRoot" value="~/media/" />
    </Parameters>
    

    My Code (AssertServerFileSystem implements IFileSystem)

    <Provider alias="media" type="UmbracoMediaAPITest.IO.AssetServerFileSystem, UmbracoMediaAPITest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
    <Parameters>
      <!--<add key="virtualRoot" value="https://api.assets.dev.webstaurantstore.com/asset-dir/clarkmarketing-local/media" />-->
    </Parameters>
    

    Inserting that assembly got Umbraco to use my custom class.

Please Sign in or register to post replies

Write your reply to:

Draft