Copied to clipboard

Flag this post as spam?

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


  • cgxcc 3 posts 33 karma points
    Mar 22, 2023 @ 09:40
    cgxcc
    0

    How to subscribe to fileupload events?

    Hi all,

    Im running latest v11 and struggling to find a solution to this.

    I need to modify filenames of uploaded media before they are committed into the ecosystem. Essentially prefixing them with a random string to further obfuscate the URL's they are accessed on.

    I've found many approaches online to acheive this including subscribing to onCreating Events but none of these appear to be in v11. Can you point me to the new methods?

    Thanks! Carl

  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Mar 22, 2023 @ 12:37
    Marc Goodson
    100

    Hi cgxcc

    Are you using the MediaService to save the uploaded file into Umbraco?

    https://docs.umbraco.com/umbraco-cms/reference/management/services/mediaservice

    or are editors just uploading new files into the Media Section?

    Either way, I think you can handle the 'MediaSavingNotification'

    https://docs.umbraco.com/umbraco-cms/reference/notifications/mediaservice-notifications

    which should be emitted just before the Media Item is saved, and I think allows you to manipulate the details of the file through the 'SavedEntities' property of the notification.

    regards

    Marc

  • cgxcc 3 posts 33 karma points
    Mar 22, 2023 @ 14:41
    cgxcc
    0

    Marc, you are a gentleman and a scholar.

    This link provided all the answers, thank you very much.

    All the best, Carl

  • cgxcc 3 posts 33 karma points
    Mar 22, 2023 @ 15:30
    cgxcc
    0

    Ah I spoke too soon.

    On further inspection it's not quite done what I thought it had.

    It did indeed change the visible file name but only within Umbraco (and not in my storage account)

    My media are currently being saved as follows:

    /media/

    Its the random 8 char string that I'm trying to make longer, or alternatively include additional random chars to the filename.png part.

    Any ideas which Notification handle this?

  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Mar 22, 2023 @ 19:41
    Marc Goodson
    0

    Hi cgxcc

    Sounds like you might want to implement your own mediapathscheme

    https://docs.umbraco.com/umbraco-cms/extending/filesystemproviders#mediapath-scheme

    This will allow you to define rules for how the media folder path is calculated...

    Regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft