I'm trying to port one of my favorite packages up to v8. The package was originally written by somebody else for v7. I can't afford to wait for the original author to migrate to v8 so I've decided to have a crack at it myself.
This particular package must support a variety of file systems, for example Azure Blob storage. In the v7 code they get an instance of the FS using the following code that no longer works in v8:
var fs = FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>();
I've had a dig through the v8 Umbraco.Core.IO source code but I can't seem to find an equivalent, so I'm assuming this way of accessing the FS has changed under the hood?
Unfortunately the docs haven't been updated yet either.
I'm not sure if this is useful or not, but there is a FileSystemsTests class within the V8 source code here, which should hopefully point you in the right direction.
As a quick reference, the line:
var fileSystem = _factory.GetInstance<IMediaFileSystem>();
Seems to be the equivalent of the V7:
var fs = FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>();
I had to stop working on this project, so I don't have an answer yet. But I'll post an update if / when I get time to resume my work. Sorry I can't be of more assistance /facepalm
There is a few different ways to access the media file system.
1. Use the static Current class (it's located in the Umbraco.Core.Composing namespace). With this, your code would look something like:
IMediaFileSystem media = Current.MediaFileSystem;
2. Use dependency injection. Whenever possible, this is the preferred way to access most services and resources in Umbraco 8.
For instance if you have a WebAPI controller, you can add the needed interfaces in the constructor of your controller, and dependency injection will do it's magic:
public class MyController : UmbracoAuthorizedApiController {
private readonly IUmbracoSettingsSection _umbraco;
private readonly IMediaFileSystem _media;
public MyController(IUmbracoSettingsSection umbraco, IMediaFileSystem media) {
_umbraco = umbraco;
_media = media;
}
[HttpGet]
public object MyMethod() {
return new {
umbraco = _umbraco?.GetType() + "",
media = _media?.GetType() + ""
};
}
}
Replacement for FileSystemProviderManager
Hi guys,
I'm trying to port one of my favorite packages up to v8. The package was originally written by somebody else for v7. I can't afford to wait for the original author to migrate to v8 so I've decided to have a crack at it myself.
This particular package must support a variety of file systems, for example Azure Blob storage. In the v7 code they get an instance of the FS using the following code that no longer works in v8:
I've had a dig through the v8 Umbraco.Core.IO source code but I can't seem to find an equivalent, so I'm assuming this way of accessing the FS has changed under the hood?
Unfortunately the docs haven't been updated yet either.
Any advice?
Cheers
Phil
I'm not sure if this is useful or not, but there is a
FileSystemsTests
class within the V8 source code here, which should hopefully point you in the right direction.As a quick reference, the line:
Seems to be the equivalent of the V7:
Hi Rhys,
I've not tested the code yet, but your reply has been super helpful - hopefully it'll work.
I'll confirm whether correct once tested.
Thanks amigo.
Hi Philip Did you find any solution? :)
I had to stop working on this project, so I don't have an answer yet. But I'll post an update if / when I get time to resume my work. Sorry I can't be of more assistance /facepalm
Hi Philip,
There is a few different ways to access the media file system.
1. Use the static
Current
class (it's located in theUmbraco.Core.Composing
namespace). With this, your code would look something like:2. Use dependency injection. Whenever possible, this is the preferred way to access most services and resources in Umbraco 8.
For instance if you have a WebAPI controller, you can add the needed interfaces in the constructor of your controller, and dependency injection will do it's magic:
is working on a reply...