U4-8852 - Meaningless exception when uploading image with missing extension

Created by Damiaan Peeters 12 Aug 2016, 14:44:12 Updated by Sebastiaan Janssen 13 Aug 2016, 09:37:11

Tags: PR

We have an UmbracoApiController where we have

if (image == null) { image = Services.MediaService.CreateMedia(fileName, folder, "CustomImageType"); } image.SetValue("umbracoFile", fileName, ms); Services.MediaService.Save(image);

This works perfectly unless you have a filename without an extension. If your filename has no extension, you will get the following exception:

System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. Parameter name: startIndex at System.String.Substring(Int32 startIndex, Int32 length) at Umbraco.Core.Models.ContentExtensions.SetFileOnContent(IContentBase content, String propertyTypeAlias, String filename, Stream fileStream) at Umbraco.Core.Models.ContentExtensions.SetValue(IContentBase content, String propertyTypeAlias, String fileName, Stream fileStream) at OurCodeFromAbove

I would expect

  • an exception telling me the extention of the filename is mandatory, or
  • just a working upload


Damiaan Peeters 12 Aug 2016, 14:48:00

note to self: make pull request to provide a check for this line https://github.com/umbraco/Umbraco-CMS/blob/75c2b07ad3a093b5b65b6ebd45697687c062f62a/src/Umbraco.Core/Models/ContentExtensions.cs#L524

Damiaan Peeters 12 Aug 2016, 15:45:33

Pull request: https://github.com/umbraco/Umbraco-CMS/pull/1434

Priority: Normal

Type: Exception

State: Open


Difficulty: Easy


Backwards Compatible: True

Fix Submitted: Pull request

Affected versions: 7.4.3

Due in version:


Story Points: