Copied to clipboard

Flag this post as spam?

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


  • John Philip 21 posts 41 karma points
    Jun 10, 2011 @ 21:04
    John Philip
    0

    Upload Media path

    Hi there

    Please could someone help me.

    I've got Umbraco installed on a sub-directory called "cms".
    I have a problem with the media path that is being generated from the template.

    • Wrong:
      ~/media/123/image.jpg
    • Correct (I need this) :
      /cms/media/123/image.jpg

    What is "~" ? And why does it insert that? Currently I'm using a field to pickup the upload:
    <umbraco:Item field="newsImage" runat="server"></umbraco:Item>

    Would really appreciate it if anyone can help me.
    Thanks so much.

    John.

  • Jonny Irwin 91 posts 153 karma points
    Jun 11, 2011 @ 10:42
    Jonny Irwin
    0

    The "~" refers to the root of your website - so if your website is located in <domain>/cms/ then the two paths above refer to the same thing.

    To get an image display you need to create either some razor or xslt as the newsImage property on your document typpe will not return a path or filename but an id.  You can use the umbraco.library as shown below if using xslt.

    <xsl:value-of select="umbraco.library:GetMedia($currentPage/newsImage,'false')/umbracoFile" />

  • John Philip 21 posts 41 karma points
    Jun 11, 2011 @ 16:38
    John Philip
    0

    Thanks so much Jonny!
    There is a another website in the root of the website domain.

    I'm currently developing the site on the /cms/ directory.

    Your sample code resulted in this when I saved it as an xslt file:

    Error occured

    System.OverflowException: Value was either too large or too small for an Int32.
    at System.Convert.ToInt32(Double value)
    at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
    at System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType)
    at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
    at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

     

    This seemed to work, but gave me the same result as my original code without the "cms" directory.

    <xsl:value-of select="$currentPage/newsImage" />
  • John Philip 21 posts 41 karma points
    Jun 27, 2011 @ 17:43
    John Philip
    0

    Does anyone know how to solve this? How could I remove the tilde?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jun 27, 2011 @ 18:11
    Jeroen Breuer
    0

    Is this what you need? http://our.umbraco.org/wiki/reference/webconfig/additional-umbraco-specific-appsettings

    There you change the media folder path.

    Jeroen

  • John Philip 21 posts 41 karma points
    Jun 27, 2011 @ 21:02
    John Philip
    0

    Jeroen, thanks so much!!!!!
    That was a really helpful link. I had looked in the config before but didn't realise you could add those values.

    You have no idea how grateful I am!

  • Robert Johansson 9 posts 30 karma points
    Aug 09, 2011 @ 16:24
    Robert Johansson
    0

    I have the same problem, a tilde is breaking my image path. What path did you add into that appsetting?

    This is how it looks at the moment: http:/xxx.local/~/media/773/design_500x360.jpg

  • John Philip 21 posts 41 karma points
    Sep 12, 2011 @ 14:56
    John Philip
    0

    Hi Robert - I think it was umbracoMediaPath - but it didn't work like I hoped in the end. Anyway, I'm off the sub domain so all works for me now. Hope you got sorted.

     

  • Greg Berlin 818 posts 634 karma points
    Mar 30, 2012 @ 01:57
    Greg Berlin
    0

    I'm pretty stuck on this one - does anybody have a solution?

    I upgraded from 4.7.0 to 4.7.1.1 and now most of the site images are broken due to that ~ at the beginning of the img src.

    I could fix with jquery but that's just ugly... surely there's a neater solution to this problem?

    Strange thing is I built a new site on 4.7.1.1 and havent experienced this issue at all on that site, which is in the same umbraco instance as the upgraded sites, which are showing the problem.

     

  • Bill 5 posts 25 karma points
    Apr 04, 2012 @ 16:01
    Bill
    0

    Greg,

    I'm trying to do an upgrade from 4.5.2 to 4.7.1.1 and it sounds like I'm running into a similar issue as you.  After the upgrade, several pages are missing all content when rendered.

    What I'm seeing is that when I try to edit the page, all of the content is there but some of the images have the path set to ~/media/... while others are just /media/...

    If I save and publish the page, it fixes the link and the page then renders properly.

    After the upgrade, I used '/Umbraco/dialogs/republish.aspx?xml=true' to refresh the entire site but that didn't fix these pages.

    So, is that what you're seeing and have you had any luck fixing it yet?  I'm working with a large site so even though save & publish is a simple fix, it's not feasible to track down all of the affected pages.

  • Greg Berlin 818 posts 634 karma points
    Apr 04, 2012 @ 16:11
    Greg Berlin
    0

    hey bill...

    yeah thats the same problem i had... my solution was to run a sql replace on the content table (can't remember which one it was - the one with the xml i think) and replace all instances with "src=\"~/" with "src=\"/" or something like that... 

    Be sure to backup your DB before you do this just in case, though for me it solved the issue. 

    Update: I found my script, here it is:

    UPDATE dbo.cmsContentXml SET xml
     =cast(replace(cast(xmlasnvarchar(max)),'img src="~/','img src="/'as ntext)

    The cast to varchar(max) is required as you can't run the replace() command on an ntext field.  Then i cast it back to ntext just in case Umbraco freaks out with having a varchar(max) field instead of ntext, though i imagine it'd be fine (it should be varchar(max) anyway)

    Hope this helps :)

     

  • Bill 5 posts 25 karma points
    Apr 04, 2012 @ 19:46
    Bill
    0

    Thanks, that helps quite a bit.  I had been looking at the cmsContentXml table but I don't do a lot with SQL, especially in the Umbraco database so that saved me some time.

    I just ran the script followed by a site republish and the handful of blank pages I'd been checking all look fine now.  Based on what I saw in the cmsContentXml table, we had a few hundred pages affected so manually re-saving would definitely not have been fun.

    FWIW, 

    I looked back at the cmsContentXml table on my production server (running 4.5.2) and it had img tags with both /media/... and ~/media/... but they all displayed fine.  I confirmed that's how my test server looked after a clone and that it still rendered the pages properly.  It was only after the upgrade to 4.7.1.1 when they stopped so I assume some peice of code in 4.7.1.1 doesn't use the ~ when it saves and so it doesn't expect the ~ to be there when rendering the page.

    In the problematic images I saw, it seemed to only be the ones which were resized for the page which had a ~ in the path.  e.g. an image in the media library that's 500x500 pixels but when inserted on a page, is set to a size of 100x100.

  • Mark Bowser 273 posts 860 karma points c-trib
    Jan 07, 2015 @ 01:34
    Mark Bowser
    0

    If I understand things correctly, there are really two levels of cache in umbraco. One level exists in that cmsContentXml table. The other level lives on disk in the App_Data/umbraco.config file. You normally don't need to think about the cache in the cmsContentXml until situations like this arise. There are also two different levels of publishing.

    Right clicking on the root content node and selecting "republish entire site" only refreshes the xml cache on disk from the cmsContentXml table. However, if you right click on a node and select publish and then check "republish children", you get a more solid publish that will refresh the data in the cmsContentXml table as well as in the cache on disk.

Please Sign in or register to post replies

Write your reply to:

Draft