Fix files and medias upload
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Linq;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Media
|
||||
@@ -121,12 +122,21 @@ namespace Umbraco.Core.Media
|
||||
}
|
||||
else
|
||||
{
|
||||
var fs = FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>();
|
||||
using (var filestream = fs.OpenFile(filepath))
|
||||
// if anything goes wrong, just reset the properties
|
||||
try
|
||||
{
|
||||
var extension = (Path.GetExtension(filepath) ?? "").TrimStart('.');
|
||||
var size = ImageHelper.IsImageFile(extension) ? (Size?) ImageHelper.GetDimensions(filestream) : null;
|
||||
SetProperties(content, autoFillConfig, size, filestream.Length, extension);
|
||||
using (var filestream = MediaHelper.FileSystem.OpenFile(filepath))
|
||||
{
|
||||
var extension = (Path.GetExtension(filepath) ?? "").TrimStart('.');
|
||||
var size = ImageHelper.IsImageFile(extension) ? (Size?)ImageHelper.GetDimensions(filestream) : null;
|
||||
SetProperties(content, autoFillConfig, size, filestream.Length, extension);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error(typeof(UploadAutoFillProperties), "Could not populate upload auto-fill properties for file \""
|
||||
+ filepath + "\".", ex);
|
||||
ResetProperties(content, autoFillConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using umbraco.editorControls.tinyMCE3;
|
||||
using umbraco.interfaces;
|
||||
using Umbraco.Web.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Tests.Models
|
||||
{
|
||||
@@ -44,9 +45,19 @@ namespace Umbraco.Tests.Models
|
||||
var mediaType = MockedContentTypes.CreateImageMediaType("image2");
|
||||
ServiceContext.ContentTypeService.Save(mediaType);
|
||||
|
||||
// reference, so static ctor runs, so event handlers register
|
||||
// and then, this will reset the width, height... because the file does not exist, of course ;-(
|
||||
var ignored = new FileUploadPropertyEditor();
|
||||
|
||||
var media = MockedMedia.CreateMediaImage(mediaType, -1);
|
||||
ServiceContext.MediaService.Save(media, 0);
|
||||
|
||||
// so we have to force-reset these values because the property editor has cleared them
|
||||
media.SetValue(Constants.Conventions.Media.Width, "200");
|
||||
media.SetValue(Constants.Conventions.Media.Height, "200");
|
||||
media.SetValue(Constants.Conventions.Media.Bytes, "100");
|
||||
media.SetValue(Constants.Conventions.Media.Extension, "png");
|
||||
|
||||
var nodeName = media.ContentType.Alias.ToSafeAliasWithForcingCheck();
|
||||
var urlName = media.GetUrlSegment();
|
||||
|
||||
|
||||
@@ -151,10 +151,10 @@ namespace Umbraco.Tests.Persistence.Querying
|
||||
DatabaseContext.Database.Execute(new Sql(string.Format("SET IDENTITY_INSERT {0} OFF ", SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName("cmsContentType"))));
|
||||
|
||||
DatabaseContext.Database.Execute(new Sql(string.Format("SET IDENTITY_INSERT {0} ON ", SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName("cmsPropertyTypeGroup"))));
|
||||
DatabaseContext.Database.Insert("cmsPropertyTypeGroup", "id", false, new PropertyTypeGroupDto { Id = 77776, ContentTypeNodeId = 99999, Text = "Group1", SortOrder = 1 });
|
||||
DatabaseContext.Database.Insert("cmsPropertyTypeGroup", "id", false, new PropertyTypeGroupDto { Id = 77777, ContentTypeNodeId = 99999, Text = "Group2", SortOrder = 2 });
|
||||
DatabaseContext.Database.Insert("cmsPropertyTypeGroup", "id", false, new PropertyTypeGroupDto { Id = 77778, ContentTypeNodeId = 99999, Text = "Group3", SortOrder = 3 });
|
||||
DatabaseContext.Database.Insert("cmsPropertyTypeGroup", "id", false, new PropertyTypeGroupDto { Id = 77779, ContentTypeNodeId = 99999, Text = "Group4", SortOrder = 4 });
|
||||
DatabaseContext.Database.Insert("cmsPropertyTypeGroup", "id", false, new PropertyTypeGroupDto { Id = 77776, UniqueId = 77776.ToGuid(), ContentTypeNodeId = 99999, Text = "Group1", SortOrder = 1 });
|
||||
DatabaseContext.Database.Insert("cmsPropertyTypeGroup", "id", false, new PropertyTypeGroupDto { Id = 77777, UniqueId = 77777.ToGuid(), ContentTypeNodeId = 99999, Text = "Group2", SortOrder = 2 });
|
||||
DatabaseContext.Database.Insert("cmsPropertyTypeGroup", "id", false, new PropertyTypeGroupDto { Id = 77778, UniqueId = 77778.ToGuid(), ContentTypeNodeId = 99999, Text = "Group3", SortOrder = 3 });
|
||||
DatabaseContext.Database.Insert("cmsPropertyTypeGroup", "id", false, new PropertyTypeGroupDto { Id = 77779, UniqueId = 77779.ToGuid(), ContentTypeNodeId = 99999, Text = "Group4", SortOrder = 4 });
|
||||
DatabaseContext.Database.Execute(new Sql(string.Format("SET IDENTITY_INSERT {0} OFF ", SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName("cmsPropertyTypeGroup"))));
|
||||
|
||||
DatabaseContext.Database.Execute(new Sql(string.Format("SET IDENTITY_INSERT {0} ON ", SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName("cmsPropertyType"))));
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace Umbraco.Web.PropertyEditors
|
||||
/// <returns>A value indicating whether a property is an upload field, and (optionaly) has a non-empty value.</returns>
|
||||
private static bool IsUploadField(Property property, bool ensureValue)
|
||||
{
|
||||
if (property.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.UploadFieldAlias)
|
||||
if (property.PropertyType.PropertyEditorAlias != Constants.PropertyEditors.UploadFieldAlias)
|
||||
return false;
|
||||
if (ensureValue == false)
|
||||
return true;
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace Umbraco.Web.PropertyEditors
|
||||
/// <returns>A value indicating whether a property is an image cropper field, and (optionaly) has a non-empty value.</returns>
|
||||
private static bool IsCropperField(Property property, bool ensureValue)
|
||||
{
|
||||
if (property.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.ImageCropperAlias)
|
||||
if (property.PropertyType.PropertyEditorAlias != Constants.PropertyEditors.ImageCropperAlias)
|
||||
return false;
|
||||
if (ensureValue == false)
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user