custom file system issue - how to 'GetUnderlyingFileSystemProvider' in v8?
hey out there,
i'm struggling a little with converting a v7 controller that force downloads a media item to v8.
the v7 code is as follows:
var fileSystem = FileSystemProviderManager.Current.GetUnderlyingFileSystemProvider("media");
var filePath = fileSystem.GetFullPath(fileUrl);
if (!fileSystem.FileExists(filePath))
{
LogHelper.Warn<FileDownloadController>("The media item was not found.");
throw new System.IO.FileNotFoundException("The media item was not found.", filePath);
}
return File(
fileSystem.OpenFile(filePath),
MimeMapping.GetMimeMapping(fileSystem.GetFileName(filePath)),
fileSystem.GetFileName(fileUrl)
);
the line i'm stuck with is:
var fileSystem = FileSystemProviderManager.Current.GetUnderlyingFileSystemProvider("media");
i've been messing around for ages trying to find the equivalent code in v8 and just can't find it...
the documentation here hasn't yet been updated for v8:
I reckon in V8 in the constructor for your controller you could inject in the IMediaFileSystem that is currently registered via DI?
using System.Collections.Generic;
using System.Web.Mvc;
using Umbraco.Web.Models;
using Umbraco8.Services;
using Umbraco.Core.Logging;
using Umbraco.Core.Services;
namespace Umbraco8.Controllers
{
public class MyCustomController : Umbraco.Web.Mvc.RenderMvcController
{
private readonly IMediaFileSystem _mediaFileSystem;
public MyCustomController(IMediaFileSystem mediaFileSystem)
{
_mediaFileSystem = mediaFileSystem;
}
public override ActionResult Index(ContentModel model)
{
// do something with MediaFileSystem
string fullPath = _mediaFileSystem.GetFullPath(path);
}
}
custom file system issue - how to 'GetUnderlyingFileSystemProvider' in v8?
hey out there,
i'm struggling a little with converting a v7 controller that force downloads a media item to v8.
the v7 code is as follows:
the line i'm stuck with is:
i've been messing around for ages trying to find the equivalent code in v8 and just can't find it...
the documentation here hasn't yet been updated for v8:
https://our.umbraco.com/documentation/Extending/FileSystemProviders/
which leaves me a little stuck! has anyone else hit this issue yet?
any suggestions, as ever, are greatly received ;)
Hi Jake
I reckon in V8 in the constructor for your controller you could inject in the IMediaFileSystem that is currently registered via DI?
Some documentation on composing here: https://our.umbraco.com/Documentation/Implementation/Composing/ and some examples of injection of services here: https://our.umbraco.com/Documentation/Implementation/Services/
regards
Marc
spot on marc, that works a treat!
now why didn't i think of that... think it may have been a case of over thinking the problem ;)
cheers fella, much appreciated.
is working on a reply...