Skip to content

Instantly share code, notes, and snippets.

@carlwoodhouse
Created May 16, 2017 19:53
Show Gist options
  • Save carlwoodhouse/b5041cb9e3fc29b5ddc75a5d94ece915 to your computer and use it in GitHub Desktop.
Save carlwoodhouse/b5041cb9e3fc29b5ddc75a5d94ece915 to your computer and use it in GitHub Desktop.
using Orchard;
using Orchard.Autoroute.Services;
using Orchard.Environment.Extensions;
using Orchard.FileSystems.Media;
using Orchard.MediaLibrary.Factories;
using Orchard.MediaLibrary.Services;
using System.Collections.Generic;
using System.IO;
namespace Patient.Framework.Media {
[OrchardSuppressDependency("Orchard.MediaLibrary.Services.MediaLibraryService")]
public class MediaService : MediaLibraryService, IMediaLibraryService {
private readonly ISlugService _slugService;
public MediaService(IOrchardServices orchardServices,
IMimeTypeProvider mimeTypeProvider,
IStorageProvider storageProvider,
IEnumerable<IMediaFactorySelector> mediaFactorySelectors,
ISlugService slugService) :
base(orchardServices, mimeTypeProvider, storageProvider, mediaFactorySelectors) {
_slugService = slugService;
}
public new string GetUniqueFilename(string folderPath, string filename) {
filename = filename.ToLower();
// slugify filename to remove spaces
filename = string.Concat(_slugService.Slugify(Path.GetFileNameWithoutExtension(filename)), Path.GetExtension(filename));
return base.GetUniqueFilename(folderPath, filename);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment