Copied to clipboard

Flag this post as spam?

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


  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jan 16, 2015 @ 15:53
    Warren Buckley
    0

    FileUpload DataType - How does it save media with IFileSystem Providers

    Hello all,
    I am trying to get my head around the source code in Umbraco and wondered if any of you smart guys are able to give me advice please.

    I want to use the IFileSystem provider that Dirk S has created for Azure Blob Storage and save other files in the media section that do not use the file upload datatype, but however pragmatically save the file via the custom File System provider to ensure the saved file also gets put into Azure blob storage.

    So for me to try & understand this I was trying to pull apart the source code in Umbraco to understand this, but I seem to be going down a rabbit hole and getting slightly lost on where to look.

    Should I be looking in the MediaService or should I be using something else to save files via the FileSystem provider in place.

    Many Thanks,
    Warren

  • Richard Soeteman 4049 posts 12922 karma points MVP 2x
    Jan 16, 2015 @ 16:06
    Richard Soeteman
    0

    Isn't this "just" handled by the provider and the Content/MediaService where you store the file using a stream?

    var doc = ApplicationContext.Current.Services.ContentService.GetById(1234);
    using (var fs = System.IO.File.OpenRead(mediaFile.FilePath))
                                        {
                                            doc.SetValue("file alias", "fileName", fs);
                                            isDirty = true;
                                        }
    
  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jan 16, 2015 @ 16:33
    Warren Buckley
    0

    Hi RIchard,
    I am not 100% sure about that.

    Here are some snippets/findings I have found:

    var fs = FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>();
    
    //Line 81 of FileUploadPropertyValueEditor.cs
    fs.DeleteFile(fs.GetRelativePath(toRemove), true);
    
    //Line 129 of FileUploadPropertyValueEditor.cs
    var umbracoFile = UmbracoMediaFile.Save(fileStream, fileName);
    
    //Method in UmbracoMediaFile.cs
    public static UmbracoMediaFile Save(Stream inputStream, string path)
    {
        var fs = FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>();
        fs.AddFile(path, inputStream);
    
        return new UmbracoMediaFile(path);
    }
    

    But the magic seems to be in the class FileSystemWrapper.cs with methods like so:

    • Get Directories
    • Delete Directory
    • Get Files
    • etc...
  • Richard Soeteman 4049 posts 12922 karma points MVP 2x
    Jan 17, 2015 @ 13:00
    Richard Soeteman
    0

    Example comes from the "official" documentation http://our.umbraco.org/documentation/Reference/Management-v6/Models/Content

    CMSImport V3 is using that as well. I think that method talks to the underlying Filesystemprovider used in filesystem code you found.

Please Sign in or register to post replies

Write your reply to:

Draft