Copied to clipboard

Flag this post as spam?

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


  • Phyxion 6 posts 26 karma points
    Apr 07, 2014 @ 12:34
    Phyxion
    0

    Replace media item in Umbraco 7.1

    We just upgraded from Umbraco 6 to Umbraco 7.1 and found out that replacing a media item no longer works? When selected a media item and 'Browse' for a new item and press 'Save' it is not uploading the file anymore like it used to do in Umbraco 6. Now we have to press 'Remove file(s)' and upload another image. But then the media id changes which we do not want. How can we actually replace an existing image? Or is this a bug in Umbraco 7.1?

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Apr 07, 2014 @ 14:20
    Sebastiaan Janssen
    0

    The media Id does not change though, just the folder the media item is in might change. I know that can be undesirable if you refer to that folder directly but that's like hardcoding the ID in your templates. Make sure to query for the media item using @Umbraco.Media(someId) or @Umbraco.TypedMedia(someId)

    Anyway, I've just tested this and it will definitely replace the media item if you just 1. "Choose file" and then 2. Save. So don't tick "Remove file(s)" and you're good to go.

    enter image description here

  • Phyxion 6 posts 26 karma points
    Apr 07, 2014 @ 14:27
    Phyxion
    0

    When you do the workaround I described the media/xxxx/ changes indeed.

    What you tested doesn't work correctly. Try this (filename is important):

    • Upload some image named a.png.
    • Open a.png with Paint and edit it a bit.
    • Upload again to Umbraco, notice there aren't any changes made to the original image.

    But here it comes:

    • Rename a.png to b.png and it does get changed.

    However, if you now rename b.png to a.png again and try to upload it, it doesn't replace the file (you get the old file). This doesn't work correctly at all and was not present in Umbraco 6.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Apr 07, 2014 @ 14:39
    Sebastiaan Janssen
    0

    Ah yup, that's a breaking change in v7. I would recommend querying media instead of hardcoding the media urls (@Umbraco.Media(someId))

  • Phyxion 6 posts 26 karma points
    Apr 07, 2014 @ 14:42
    Phyxion
    0

    Can you use the @Umbraco.Media(someId) in the editor then? I need to insert an image in the text I'm writing. I don't think that was possible in Umbraco 6, but maybe in 7?

Please Sign in or register to post replies

Write your reply to:

Draft