Fixing potential NRE in media profiles

This commit is contained in:
Sebastien Ros
2013-10-21 16:48:49 -07:00
parent b43453a0f1
commit a69087c7bf
2 changed files with 11 additions and 4 deletions

View File

@@ -8,7 +8,6 @@ using Orchard.Forms.Services;
using Orchard.Localization;
using Orchard.MediaProcessing.Descriptors.Filter;
using Orchard.MediaProcessing.Services;
using Orchard.Utility.Extensions;
namespace Orchard.MediaProcessing.Providers.Filters {
public class ResizeFilter : IImageFilterProvider {
@@ -72,7 +71,7 @@ namespace Orchard.MediaProcessing.Providers.Filters {
if (context.Media.CanSeek) {
context.Media.Seek(0, SeekOrigin.Begin);
}
ImageBuilder.Current.Build(context.Media, result, settings);
ImageBuilder.Current.Build(context.Media, result, settings, true);
context.Media = result;
}

View File

@@ -110,6 +110,10 @@ namespace Orchard.MediaProcessing.Services {
var filterContext = new FilterContext { Media = image, FilePath = _storageProvider.Combine("_Profiles", _storageProvider.Combine(profileName, CreateDefaultFileName(path))) };
if (image == null) {
return filterContext.FilePath;
}
var tokens = new Dictionary<string, object>();
// if a content item is provided, use it while tokenizing
if (contentItem != null) {
@@ -160,14 +164,18 @@ namespace Orchard.MediaProcessing.Services {
// TODO: Update this method once the storage provider has been updated
private Stream GetImage(string path) {
if (path == null) {
throw new ArgumentNullException("path");
}
var storagePath = _storageProvider.GetStoragePath(path);
if (storagePath != null) {
try {
var file = _storageProvider.GetFile(storagePath);
return file.OpenRead();
}
catch {
Logger.Error("path:" + path + " storagePath:" + storagePath);
catch(Exception e) {
Logger.Error(e, "path:" + path + " storagePath:" + storagePath);
}
}