Copied to clipboard

Flag this post as spam?

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


  • Rob de Mercado 32 posts 148 karma points
    Jul 01, 2020 @ 15:24
    Rob de Mercado
    0

    Getting media picker item umbracoBytes in Umbraco 8.5.5

    For accessibility purposes when linking to a media item (say PDF) in the rich text editor I developed a way (in controllers.js) of appending the file extension and size attributes to the link text.

    The controller is Umbraco.Editors.LinkPickerController. Here is my Umbraco 7 code block

           $scope.switchToMediaPicker = function () {
            userService.getCurrentUser().then(function (userData) {
                $scope.mediaPickerOverlay = {
                    view: 'mediapicker',
                    startNodeId: userData.startMediaIds.length !== 1 ? -1 : userData.startMediaIds[0],
                    startNodeIsVirtual: userData.startMediaIds.length !== 1,
                    show: true,
                    submit: function (model) {
                        var media = model.selectedImages[0];
                        $scope.model.target.id = media.id;
                        $scope.model.target.udi = media.udi;
                        $scope.model.target.isMedia = true;
                        //derive file name, extension and size in KB and set to target.name
                        var filename, fileext, sizeKBytes
                        angular.forEach(media.properties, function (property) {
                            if (property.alias === "umbracoExtension") {
                                fileext = " [" + property.value + "] ";
                                if (media.name.endsWith("." + property.value)) {
                                    filename = media.name.substring(0, media.name.length - (property.value.length + 1));
                                }
                                else {
                                    filename = media.name;
                                }
                            }
                            else if (property.alias === "umbracoBytes") {
                                sizeKBytes = parseInt(property.value / 1024) + "KB";
                            }
                        });
                        $scope.model.target.name = filename + fileext + sizeKBytes;
                        $scope.model.target.url = mediaHelper.resolveFile(media);
                        $scope.mediaPickerOverlay.show = false;
                        $scope.mediaPickerOverlay = null;
                    }
                };
            });
        };
    

    In Umbraco 8 there is no media.properties collection available.

    There are no services injected which seem to allow me to access media entity properties.

    Please advise how I would get the umbracoBytes value of a selected media item in Umbraco 8.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies