Copied to clipboard

Flag this post as spam?

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


  • Dan White 206 posts 510 karma points c-trib
    Jan 05, 2015 @ 22:54
    Dan White
    0

    Handling Media within RTE

    How do you handle the migration of media that are referenced within a RTE?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jan 05, 2015 @ 23:16
    Alex Skrypnyk
    0

    Hi Dan,

     

    What do you mean migration ? 

    Removing it from media section ? 

     

    Thanks

  • Dan White 206 posts 510 karma points c-trib
    Jan 05, 2015 @ 23:21
    Dan White
    0

    I mean copying the images or documents from my current site to the new install. My current site contains rich text editors that insert images and link to documents from the media section. The content (text) uMirror handles fine, but obviously the documents and media that are linked to from within those RTEs is not being copied over, resulting in broken links. This is to be expected, but I'm not sure how to properly solve it.

  • Antoine 176 posts 1494 karma points
    Mar 25, 2015 @ 10:23
    Antoine
    0

    Hi Dan and sorry for my late answer. All this stuff has to be done into a proxy method, I give you a example:

    In this case, we keep the media folder structure between both Umbraco instances.

    First, you can match all your RTE media dependency within the proxy method this way:

    foreach (Match index in Regex.Matches(your-legacy-umbraco.config, "[\"]/media/(.+?)[\"]", RegexOptions.IgnoreCase))
    {
    AutoFillMedia(index.Value.Replace("\"", ""), ref your-legacy-umbraco.config);
    }

    The AutoFillMedia method create a new Media and change its path within the your-legacy-umbraco.config

    private static void AutoFillMedia(String mSrcLegacy, ref String umbracoconfig)
    {
        if (File.Exists(HttpContext.Current.Server.MapPath("path to your legacy's media files" + mSrcLegacy)))
        {
            var mFolderPath = GetMediaPathBySrc(mSrcLegacy);
            var mFilePath = HttpContext.Current.Server.MapPath("path to your legacy's media files" + mSrcLegacy);
    
            var mParentId = Lecoati.uMirror.Core.Util.GetMediaParentId(mFolderPath);
            var mNewId = Lecoati.uMirror.Core.Util.SaveMedia(mFilePath, mParentId);
            var mNew = ApplicationContext.Current.Services.MediaService.GetById(mNewId);
    
            if (mNew != null && mNew.HasProperty("umbracoFile"))
                umbracoconfig = umbracoconfig.Replace(mSrcLegacy, mNew.GetValue("umbracoFile").ToString());
        }
    }

    We added some helper methods within uMirror core to make some Media manipulation:

    • GetMediaParentId: look for a specific media folder by path (ex: /home/banner ), if the path doen't existe, it creates it
    • SaveMedia: save the media file

    The Method GetMediaPathBySrc looks for the legacy media path:

    private static string GetMediaPathBySrc(string mediaPath)
    {
        string url = "Rest service from the legacy website which return the media path";
        using (WebClient client = new WebClient())
        {
            return client.DownloadString(string.Format(url, mediaPath));
        }
    }

    The Rest service from the legacy structure is quite easy to implement, let me know if you have any question about it, I can look after this specific method.

     

     

Please Sign in or register to post replies

Write your reply to:

Draft