Copied to clipboard

Flag this post as spam?

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


  • person2 11 posts 81 karma points
    May 04, 2020 @ 12:07
    person2
    0

    Adding custom properties to media uploads

    I have been working on automatically resizing images upon upload in the Umbraco backoffice and have got a working solution thanks to the posts here:

    https://our.umbraco.com/forum/umbraco-7/using-umbraco-7/62022-Umbraco-7-grid-and-image-resizing

    https://our.umbraco.com/forum/umbraco-7/using-umbraco-7/64007-Umbraco-7-Image-Resizing-(Media-Library-RTE

    Now I am trying to implement a checkbox which will disable the automatic resizing if a user wants to upload a large image for a background.

    I have put a checkbox in the umb-file.dropzone.html

    Within this html there is a onChange listener that calls the handleFiles() function on upload, which I tracked down in the umbraco.controllers.js file and I have the value of the checkbox within this file which is good.

    This then calls the upload() function and I am wondering how I can add custom properties or simply pass a boolean checkbox value from the upload() function so that I can parse that data in my MediaService.Saving event.

    The MediaService.Saving event has two parameters MediaService.Saving += (sender, args) but am having trouble adding some custom property into the args object.

    TLDR: Trying to read the value of a checkbox in umb-file.dropzone.html from the MediaService.Saving event

    Any help or tips in the right direction are appreciated. Cheers

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    May 04, 2020 @ 12:31
    Nik
    0

    Hi "person2",

    I highly recommend looking for an alternative way to do this as modifying core Umbraco files will cause you issues with upgrades and your changes being lost / breaking core Umbraco behaviour.

    Also, it's important to be aware that this component is probably used in the "media picker" upload that shows in the media picker, the RTE media picker, and other areas.

    (Sorry it's not a helpful response on how to resolve the issue)

    It might be possible to use something like an injector/interceptor (I don't know the correct term I'm affraid), to intercept the file upload request and direct it to your own Angular Controller/Service, which could in turn add information to the upload post, which, again would need to go to your own C# API controller to update a field on your media item.

    Once the media item has the updated value, then you should see it in your MediaService.Saving event as a property on the media item.

    Thanks

    Nik

  • person2 11 posts 81 karma points
    May 04, 2020 @ 12:46
    person2
    0

    Thanks "Nik"

    I highly recommend looking for an alternative way to do this as modifying core Umbraco files will cause you issues with upgrades and your changes being lost / breaking core Umbraco behaviour.

    I have only changed a few lines and accept that this could break and I will have to maintain this when upgrading versions.

    Hopefully someone else has some ideas, otherwise my fallback plan is to ask any users uploading images to append "-noResize" or something unique/identifiable to the filename of the image. I can then parse this within the MediaService.Saving event.

    Although a checkbox upon upload would be better!

  • person2 11 posts 81 karma points
    May 04, 2020 @ 12:56
    person2
    0

    If I do go the route of parsing the filename of the image in the MediaService.Saving event....

    Do you know where I can programmatically append text to the end of the filename before it hits the MediaService.Saving event?

Please Sign in or register to post replies

Write your reply to:

Draft