Issue U4-5572 convert file name to friendly media item name
This commit is contained in:
@@ -105,8 +105,8 @@ namespace Umbraco.Core
|
||||
//if the resolution was success, return it, otherwise just return the path, we've detected
|
||||
// it's a path but maybe it's relative and resolution has failed, etc... in which case we're just
|
||||
// returning what was given to us.
|
||||
return resolvedUrlResult.Success
|
||||
? resolvedUrlResult
|
||||
return resolvedUrlResult.Success
|
||||
? resolvedUrlResult
|
||||
: Attempt.Succeed(input);
|
||||
}
|
||||
}
|
||||
@@ -128,7 +128,7 @@ namespace Umbraco.Core
|
||||
}
|
||||
|
||||
internal static readonly Regex Whitespace = new Regex(@"\s+", RegexOptions.Compiled);
|
||||
internal static readonly string[] JsonEmpties = new [] { "[]", "{}" };
|
||||
internal static readonly string[] JsonEmpties = new[] { "[]", "{}" };
|
||||
internal static bool DetectIsEmptyJson(this string input)
|
||||
{
|
||||
return JsonEmpties.Contains(Whitespace.Replace(input, string.Empty));
|
||||
@@ -1470,5 +1470,29 @@ namespace Umbraco.Core
|
||||
byte[] hash = md5.ComputeHash(myStringBytes);
|
||||
return new Guid(hash);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Converts a file name to a friendly name for a content item
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
public static string friendlyNameFromFilename(this string fileName)
|
||||
{
|
||||
// strip the file extension
|
||||
fileName = StripFileExtension(fileName);
|
||||
|
||||
// underscores and dashes to spaces
|
||||
fileName = ReplaceMany(fileName, new char[] { '_', '-' }, ' ');
|
||||
|
||||
// any other conversions ?
|
||||
|
||||
// Pascalcase (to be done last)
|
||||
fileName = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(fileName);
|
||||
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,15 +534,7 @@ namespace Umbraco.Web.Editors
|
||||
if (UmbracoConfig.For.UmbracoSettings().Content.ImageFileTypes.Contains(ext))
|
||||
mediaType = Constants.Conventions.MediaTypes.Image;
|
||||
|
||||
//TODO: make the media item name "nice" since file names could be pretty ugly, we have
|
||||
// string extensions to do much of this but we'll need:
|
||||
// * Pascalcase the name (use string extensions)
|
||||
// * strip the file extension
|
||||
// * underscores to spaces
|
||||
// * probably remove 'ugly' characters - let's discuss
|
||||
// All of this logic should exist in a string extensions method and be unit tested
|
||||
// http://issues.umbraco.org/issue/U4-5572
|
||||
var mediaItemName = fileName;
|
||||
var mediaItemName = fileName.friendlyNameFromFilename();
|
||||
|
||||
var f = mediaService.CreateMedia(mediaItemName, parentId, mediaType, Security.CurrentUser.Id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user