Copied to clipboard

Flag this post as spam?

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


  • daniel 7 posts 37 karma points
    Jan 30, 2019 @ 21:18
    daniel
    0

    Image deleted in media tied to content

    Hello community

    How to avoid the problem that deletes an image that is tied to a content and is a mandatory field of the document type is eliminated and in the content the image is as trashed.

    As valid that the image always exists and is not as deleted.

    Thanks

  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Jan 30, 2019 @ 22:53
    Marc Goodson
    100

    Hi Daniel

    Have a look at this packaged called 'nexu'

    https://our.umbraco.com/packages/backoffice-extensions/nexu/

    this will add additional functionality to Umbraco, that should give you a warning if you try to delete things, when they are used in other parts of Umbraco.

    I think that is the problem you are describing?

    It's a good package to look at anyway :-)

    regards

    Marc

  • daniel 7 posts 37 karma points
    Jan 30, 2019 @ 23:44
    daniel
    0

    Hi Marc.

    Exactly that is what I would like to prevent from happening.

    It would be excellent if umbraco implemented this functionality as something native.

    Although it seems the best thing is always to verify that the image is not null to avoid problems of type "Object reference not set to an instance of an object."

    I appreciate your response and I will take a look at the recommended package.

    regards

    Daniel B.

  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Jan 31, 2019 @ 15:46
    Marc Goodson
    0

    Yes

    That and always checking for nulls :-P

  • Dean Wiseman 26 posts 115 karma points
    Mar 04, 2020 @ 14:47
    Dean Wiseman
    0

    I just encountered this issue with a live site. An image tied to a post was deleted from the media folder causing the news feed to throw a null reference error when it accessed the post with the missing image. I resolved the issue by restoring the image from the recycle bin. I'm using Umbraco version 8+ which I don't think the Nexu package is compatible with. Any other suggestions for this issue?

  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Mar 04, 2020 @ 19:16
    Marc Goodson
    1

    Hi Dean

    The best defence is to always check for nulls.

    So if you have an implementation for a News Story that has a Media Picker to pick the main image you might have something like

    @{
    var relatedImage = Model.Value<IPublishedContent>("relatedImage");
    }
    
    <img src="@relatedImage.Url" alt="@relatedImage.Name" />
    

    The danger here is if the picked image has been deleted, the relatedImage object will be null and the call to .Url will throw an error.

    @{
    var relatedImage = Model.Value<IPublishedContent>("relatedImage");
    bool hasRelatedImage = relatedImage!=null;
    }
    @if(hasRelatedImage){
    <img src="@relatedImage.Url" alt="@relatedImage.Name" />
    }
    

    will not throw an error, because before we try to access the Url property we check first if the object is null...

    Umbraco 8.6 will include 'Media Tracking' in a similar fashion to the Nexu package - https://umbraco.com/blog/umbraco-product-update-january-29th-2020/ so it will be easier to see if a Media item is in use before deleting it!

    There was an early content app for V8 that tracked where Nodes were used: https://our.umbraco.com/packages/backoffice-extensions/linked-nodes-content-app/

    regards

    Marc

  • Dean Wiseman 26 posts 115 karma points
    Mar 04, 2020 @ 21:21
    Dean Wiseman
    0

    I thought I did but I guess I missed a reference to an image for most recent articles in a partial used for the footer. Fixed now. :-)

Please Sign in or register to post replies

Write your reply to:

Draft