FileSystems - Can I register my own in FileSystems...
# help-with-umbraco
w
So we have mvcViewFileSystem and CSS, Scripts and Media etc. is there a way to extend this so I have my customDataFileSystem that I can then register/use an IFileProvider such as Azure Blob or change it to a PhysicalFileSystem or even AWS. Can this be done today and if so how, as I can’t piece it together atm. https://cdn.discordapp.com/attachments/1248370352908931092/1248372789975584778/IMG_0152.png?ex=66636d42&is=66621bc2&hm=ce2fbf2157ef2430acadd6ebb67195e2628bccd69ec57887e350eb6929467047&
r
Besides media, I think you can only replace the Stylesheet Filesystem https://docs.umbraco.com/umbraco-cms/extending/filesystemproviders#other-ifilesystems
w
Hmm was hoping to extend it @rasmusjp Thought Forms or perhaps Deploy implemented their own FileSystems (but maybe I am remembering it all wrong)
k
It's doable, we've done it for the uSync restore feature (backups to azure blobs!). I will dig out some code for you. But it's not to complex
(well I would if I could get azure DevOps to copy things in my phone!)
w
Ah superstar Kevin
Any luck @Kevin Jump ?
k
yeah first time back at the computer. So what we do with the restore, is very simialr as to how forms does it for azure, the core azure file provider does all the work and you register your own folder against it. code files in a gist here https://gist.github.com/KevinJump/c2b229b610157de851fe720b1c94a340 ouitline is. 1. we use the PhysicalFileSystem by default. as our file provider 2. we have an azure extension that registers a route using the azure file provider 3. we have a AddRestoreFileSystem method as na extension that registers the file system with one of these providers. 4. our
RestoreFileManager
class takes the fileSystem and does all its IO against that. e.g in the restore code we have:
Copy code
cs
 using (var stream = _fileSystem.OpenFile(archiveFile))
 {
     _syncFileService.SaveFile(targetFile, stream);
 }
grabs a zip file from the blob, and saves it in temp storage where we unzip it (we could do this in memeory, but its was just simpler to copy)
r
Ahhh... I see, I misunderstood the question, read it as you wanting to replace them with your own implementation. And yes, Forms make it possible to change the filesystem used for storing prevalue files. Kevin's gist should do what you want. I've been told (think it might've been by Shannon) that filesystems should be wrapped with the
ShadowWrapper
(e.g. like it's done with [media](https://github.com/umbraco/Umbraco-CMS/blob/46c0b66a70f2c2255c953763c8fc41387980335c/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Uniques.cs#L147-L165)) but I don't remember why
I guess reading the comment might help 🤦‍♀️ it's to do with scoping, I guess it's so the actions only will be executed if the scope is completed
w
Thanks both. Will have a proper look on Monday
10 Views