Copied to clipboard

Flag this post as spam?

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


  • Alan 3 posts 23 karma points
    Feb 11, 2011 @ 13:52
    Alan
    0

    Images url changes after save or publish

    Hi Guys,

    Im having an issue in 4.5.2 with images that I insert into my RTE not displaying when saved or published.

    Basically I have set up Umbraco in a folder off the wwwroot. So my index page would be http://localhost/mysite/

    I have added an image to the media section and use the "Insert/Edit image" button to add the image to my text box. The image displays fine in the editor untill I click Save or Save and Publish.

    It then seems to cut the url from /mysite/media/299/image.jpg  to  /media/299/image.jpg and the image doesnt display correctly on the site or in my RTE.

    Does anyone know how I can fix this? Is it a setting or something that I am missing?

    I would really appreciate any help you guys could give me.

    Thanks,

    Alan

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Feb 11, 2011 @ 14:22
    Tom Fulton
    0

    Hi Alan,

    This was a known bug in 4.5.2 when running Umbraco in a virtual directory instead of the root..  I just checked the Codeplex ticket and it looks like it was fixed for 4.6, but I have not had a chance to test it yet.

    So your workaround would be to upgrade to 4.6.1 or run Umbraco on the website root instead :)

    Thanks,
    Tom

  • Alan 3 posts 23 karma points
    Feb 11, 2011 @ 16:41
    Alan
    0

    Hey Tom,

    Thanks for that.

    Im guessing it wasnt just a small change that I could incorprate into my instance of Umbraco?

    Ill have to see if I can do as there are other stuff running on the production server so I dont think they would want all the Umbraco files in the wwwroot folder and I know upgrading to 4.6.1 involves upgrading .Net 4 as well as possible other things so I would have to see if they are prepared to do an upgrade and what the knock on effects would be.

    Anyway thanks for your help.

    Alan

  • Jannie Brand 3 posts 23 karma points
    Apr 01, 2011 @ 08:56
    Jannie Brand
    0

    I had the exact same problem and am also running Umbraco 4.5.2. I also can't upgrade as clients' server doesn't support .Net 4.0, so I had to try and find a fix somehow. After hours of struggling I finally found a solution that works for me. It's not a perfect solution, but like I said ... it works for me.

    I just want to mention that I used umbraco for the backend and the nodeFactory for the frontend as the client already had a .Net website and just wanted to be able to update the news section.

    In the Umbraco backend I had the same problem as mentioned above: "I have added an image to the media section and use the "Insert/Edit image" button to add the image to my text box. The image displays fine in the editor untill I click Save or Save and Publish.". I used a jQuery script to edit the image path and get the images to display correctly. I added the following script to the "editContent.aspx" (located in "umbraco\editContent.aspx"), right at the bottom (just above the "" line):


            <script type="text/javascript">
                $("#right").ready(function() {
                    setImagePath();
                });
             
                function setImagePath() {
                    if ($("#ctl00_body_bodyText_ifr").attr("src") == "javascript:\"\"") {
                        $("#ctl00_body_bodyText_ifr").contents().find("img").attr("src", function() {
                            return this.src.replace('/media/',window.location.pathname.replace("/umbraco/editContent.aspx","") + '/media/');
                        });
                    } 
                    else {
                        setTimeout("setImagePath()",500);
                    }
                }
            </script>

    Then for the frontend I used a string replace to fix the image path. Here is a simplified version of the code:

            Node node = new Node(-1);  //Get all data in the umbraco.config
            Nodes childNodes = node.Children;

            foreach (Node childNode in childNodes)
            {
              switch (childNode.NodeTypeAlias)
              {
                case "NewsArea":
                  foreach (Node childNodeItem in childNode.Children) //NewsItem
                  {
                    string strImagePath = "";
                   
                    try    //Get Media File Path
                    {
                      Media file = new Media(int.Parse(childNodeItem.GetProperty("newsImage").Value));
                      strImagePath = file.getProperty("umbracoFile").Value.ToString();
                    }
                    catch { }

                    if (strImagePath != "")
                      litNews.Text += "<img src=\"" + strImagePath.Replace("~/", "") + "\" border=\"0\" alt=\"\" />";
                   
                    litNews.Text += childNodeItem.GetProperty("bodyText").Value.Replace("=\"/media/","=\"media/");
                  }
                  break;
                default:
                  break;
              }
            }

    Hopefully it'll work for someone else or help them in the right direction.

    Jannie ;-)

  • 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