Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • steschu 88 posts 489 karma points
    Feb 20, 2020 @ 11:15
    steschu
    0

    Keep original filename in filesystem for uploaded file

    Hello,

    I noticed that the names of files that are uploaded to the file system in the media folder are automatically changed by Umbraco.

    E.g. when I place a file with original name "Text 1.2.3.txt" in the umbracoFile property, it is uploaded to /media/

    I don't know since when this behaviour is implemented, but it is not suitable for my needs.

    I tried to add some logic to the MediaService.Saving event, but this seems to be the wrong place, because the file has already been changed then.

    Can anybody help here?

    Kind regards, Stephan

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Feb 20, 2020 @ 13:00
    Dan Diplo
    0

    A file is a media type that has properties, including the name. As far as I know the name will get modified to make it more human friendly (which makes sense) but the actual filename itself doesn't change. So you should be able to access the URL property to get the original filename, if needed.

  • steschu 88 posts 489 karma points
    Feb 20, 2020 @ 14:02
    steschu
    0

    Hi Dan,

    Unfortunatley the file itself is beeing renamed the way I described above. So a user that uploads a file and later downloads it will get differently named files. I guess this is somewhere done in the Angular JS code, but I am still searching the code part where it is done...

    Stephan

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Feb 20, 2020 @ 14:10
    Dan Diplo
    0

    Ahh, never realised it renamed the file name, too. I that case, check the PR that added this renaming - it has some useful info and a Gist from Seb to revert the renaming.

    https://github.com/umbraco/Umbraco-CMS/issues/2943

  • steschu 88 posts 489 karma points
    Feb 20, 2020 @ 15:51
    steschu
    0

    Hi Dan,

    Yes, I found that issue some days ago, but this also is not the problem. The issue describes how to disable the friendly name functionality for the name property of the file. I also replied to that issue.

    But this still does not solve the problem that the uploaded file itself is renamed. I have not found any evidence in the Angular JS code which is responsible for it.

    So it must happen in the C# Code. Since the file is already renamed in the MediaService.Saving event, it must happen somewhere before...

    Stephan

  • steschu 88 posts 489 karma points
    Feb 28, 2020 @ 08:59
    steschu
    0

    I have not found a solution yet. Can anybody help?

  • steschu 88 posts 489 karma points
    Mar 16, 2020 @ 16:17
    steschu
    101

    Hello,

    Found out, that you have to change the Umbraco distribution and compile an own version of it.

    1. In Umbraco.Web.Editors.MediaController.cs

    Change line 796 to

    // var mediaItemName = fileName.ToFriendlyName();
    var mediaItemName = fileName;
    

    This will set the Media name o exactly the file name when creating a Media item via the direct upload or drag & drop.

    1. In Umbraco.Core.IO.MediaFileSystem.cs

    Comment line 149

    // filename = IOHelper.SafeFileName(filename.ToLowerInvariant());
    

    This will keep your uploaded file name when saving the file to the file system.

    Of course one must know that it is absolutely sensible to rename a file to a web-safe filename when uploading. But there might be some cases where this behavour is not wanted.

    Kind regards, Stephan

  • LOGISZ 2 posts 72 karma points
    Jan 31, 2022 @ 08:42
    LOGISZ
    0

    This is in the Core from Umbraco and is not what we want to change there. Is there an option to disable this functionality or to create our own functionality for this name changing event.

  • LOGISZ 2 posts 72 karma points
    Mar 16, 2022 @ 22:44
    LOGISZ
    0

    Anybody with an sollution for this?

Please Sign in or register to post replies

Write your reply to:

Draft