Copied to clipboard

Flag this post as spam?

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


  • Ron Brouwer 273 posts 768 karma points
    Oct 22, 2009 @ 09:58
    Ron Brouwer
    0

    Problem with spaces in media filename

    Hi,

    Assuming that a file is uploaded with a space in the filename like "myimage home.jpg".

    background:url(umbraco.library:GetMedia(data [@alias='afbeelding'], 0)/data [@alias='umbracoFile']) no-repeat

    resulting in:

    background:url(/media/23609/myimage home.jpg) no-repeat 

    Using the above method won't work.

    How can I get around this problem withoud having to split the "umbracofile" string and use urlencoding on the filename alone?

    Ron

     

     

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Oct 22, 2009 @ 12:09
    Douglas Robar
    0

    You really ought to include quotes with the url tag, which would resolve the problem I think.

    The output you're looking to generate would be

    background:url("/media/23609/myimage home.jpg") no-repeat

    cheers,
    doug.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Oct 22, 2009 @ 21:59
    Kim Andersen
    1

    Wich browser do you use Ron?

     

    Sometimes Internet Explorer can have different issues with filenames. One of them is when a "space" is a part of the filename just like in your example. Other things such as uppercase letters or special characters(æ, ø, å, ö, ó etc.) can mess things up.

     

    It's a good idea to only include lowercase characters, underscore(_) and hyphens(-) in your filenames. 

     

    But Doug also have a point. Sometimes quotes can make a difference as well.

     

    And by the way. Remember the semicolon (;) at the end after the no-repeat.

  • Ron Brouwer 273 posts 768 karma points
    Oct 23, 2009 @ 09:12
    Ron Brouwer
    1

    Thats right Douglas, I already figured that out..

    However it would be nice if it could be encoded.
    But my problem is solved for now.

    Ron

  • Ron Brouwer 273 posts 768 karma points
    Oct 23, 2009 @ 09:14
    Ron Brouwer
    0

    @kim "It's a good idea to only include lowercase characters, underscore(_) and hyphens(-) in your filenames. "

    thats what I tel my clients but they won't listen :p

  • Jonas Eriksson 930 posts 1825 karma points
    Mar 19, 2010 @ 13:27
    Jonas Eriksson
    0

    Bumping into this post. Filenames with spaces and non-english characters also causes validation errors. I agree that it would be nice if it could be encoded as Ron said. Files can be saved that way in all kinds of os'es but the web does not like it so encoding should be the way to do it.

  • dandrayne 1138 posts 2262 karma points
    Mar 19, 2010 @ 14:18
    dandrayne
    0

    umbraco.library:UrlEncode might help here, but there does come a point where the client needs to continue any validation efforts!

  • Jonas Eriksson 930 posts 1825 karma points
    Mar 31, 2010 @ 22:39
    Jonas Eriksson
    0

    We used Media.SaveEventHandler() to handle this. Few lines of code. It resaves with nice name + changes the filename property. Works fine as far as I've tested yet, need some more testing + add the thumbnail, if there's interest we'll upload it as a small package (only include the dll and voila).

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 31, 2010 @ 22:47
    Jan Skovgaard
    0

    Hi Jonas

    That sounds like a good package - Please consider adding it to our :-)

    Cheers

    /Jan

  • Martin Rud 260 posts 1001 karma points c-trib
    May 25, 2010 @ 13:59
    Martin Rud
    0

    Hi Jonas,

    I would like that package too. :)

    Have you considered uploading it to Our?

     

    Cheers,

    Martin

  • Jonas Eriksson 930 posts 1825 karma points
    May 27, 2010 @ 13:28
    Jonas Eriksson
    0

    Hi, yes, we made such a function, but it breaks Multiple File Upload at the moment, thats why it's still not published anywhere. My approach for it to run at the moment is to run once on a nightly schedule.

    Regards

    Jonas Eriksson

  • Martin Rud 260 posts 1001 karma points c-trib
    May 29, 2010 @ 10:19
    Martin Rud
    0

    Hi Jonas,

    Ok - thanks for your answer. :)

    Is it possible for you to share the lines of code, not necessarily the whole package? Then we can implement and use it on our own risk.

    Cheers,

    Martin

  • Jonas Eriksson 930 posts 1825 karma points
    Jun 16, 2011 @ 07:20
    Jonas Eriksson
    0

    Hi, just one year late ... I stumbled on this thread and noticed I forgot to respond with the link to the wiki where the snippet is : http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events/event-examples/adjust-media-file-so-it's-url-friendly

Please Sign in or register to post replies

Write your reply to:

Draft