Copied to clipboard

Flag this post as spam?

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


  • Ilse 2 posts 22 karma points
    25 days ago
    Ilse
    0

    Umbraco 14 - Context API help needed!

    Hi there!

    I'm trying to add some functionality within the new Umbraco 14 backoffice. Whenever a user selects an image to upload, I want to read the base64 image in order to figure out the size of the image, and give a notification based on this data. I have successfully created a workspace context that loads whenever the 'upload file' modal opens. I'm also able to consume the notification context and show the required notifications.

    Problem: I'm trying to consume the media workspace context within my workspace and listen to a change within the Umbraco Image Cropper. This way I can receive the temporary image data within my own workspace once it has been selected within the cropper.

    I have tried receiving data through several methods within the media workspace context class, but I have not yet found an answer. I'd love to get some help from more experienced developers to know what things I'm missing. Thank you! :)

  • Ilse 2 posts 22 karma points
    24 days ago
    Ilse
    0

    This is my current code; it properly listens to the umbracoFile field, but only receives an object with a temporaryFileId in there. The src is an empty string, assuming this gets filled only when the image is confirmed/uploaded. Does anybody know how to obtain the temporary file (base64) itself within my code?

    host.consumeContext(UMB_MEDIA_WORKSPACE_CONTEXT, (instance: UmbMediaWorkspaceContext) => {
        instance.createPropertyDatasetContext(host, undefined);
    
        host.consumeContext(UMB_PROPERTY_DATASET_CONTEXT, async (instance: UmbPropertyDatasetContext) => {
            this.observe(await instance.propertyValueByAlias('umbracoFile'), (value: {temporaryFileId: string, src?: string}) => {
                console.log('the value is', value)
    
                if (value !== undefined && value.temporaryFileId !== null && value.temporaryFileId !== undefined) {
                    host.consumeContext(UMB_NOTIFICATION_CONTEXT, (instance: UmbNotificationContext) => {
                        this.notify(instance);
                    });
                }
            });
        });
    });
    
Please Sign in or register to post replies

Write your reply to:

Draft