More in this section

Forums / General Discussions / Image URLs in album

Image URLs in album

4 posts, 1 answered
  1. Eric
    Eric avatar
    147 posts
    Registered:
    12 Nov 2007
    13 Jan 2011
    Link to this post
    Say I have an album called "users". In the album, I optionally upload a photo for users on the site. So I have two users: Abby and Betty. Betty has a photo, but Abby does not. I know what the name of the photo will be (i.e. betty.jpg) and that it will be in the "users" folder, however, I don't know what day it was uploaded.

    The URL for the image will be something like: http://localhost/images/users/2011/01/13/betty.jpg
    But I'd prefer http://localhost/images/users/betty.jpg

    That way, I could easily check to see if the image exists with some JavaScript like the following
    $(document).ready(function () {
        var url = '/images/users/betty.jpg';
        var img = new Image();
        img.onload = function () { $('img#me').attr('src', url); };
        img.onerror = function () { $('img#me').hide(); };
        img.src = url;
    });

    But since the the images have date parts in their URL, I can't do this. I suspect I'd have to do some kind of query via the API to find the image to find the full URL.

    Is there any way to upload images without dates in the URL and go directly into the album folder?

    Thanks,
    Eric
  2. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    13 Jan 2011
    Link to this post
    Hi Eric,

    If you want to change how item URLs are constructed, you have to provide a different format in the configuration of your data provider. For your specific case with images, before you upload images, do the following:

    1. Go to Administraion -> Settings in the backend.
    2. Click the "Advanced" link near the header.
    3. In the treeview on the left expand the sections Libraries -> Providers -> OpenAccessDataProvider -> Parameters.
    4. When you click the Parameters section, there will be a "Create New" button in the right-hand side. Click it.
    5. For Key enter "urlFormat". For value enter "/[UrlName]". All without the quotes.
    6. Click Save Changes.

    What this effectively does is change the URL format of the libraries data provider from the default (including a date) to only showing the UrlName of the item. You should be all set and all the images you upload after that will have URLs without dates.

    Note that this will also affect ALL VIDEOS AND DOCUMENTS. This is a provider-level setting and affects all items in Libraries. If you don't want that side effect, you would have to parse the URLs in your javascript with regular expressions to exclude the date.

    Don't hesitate to ask any further questions you may have.

    Best wishes,
    Slavo
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  3. Kevin
    Kevin avatar
    19 posts
    Registered:
    30 Sep 2010
    08 Mar 2011
    Link to this post
    I followed Slavo's instructions and still have dates in the images I upload. I want to do exactly what Eric posted, that is, remove the dates from image URLs.

    What else should I try?
  4. Kevin
    Kevin avatar
    19 posts
    Registered:
    30 Sep 2010
    08 Mar 2011
    Link to this post
    Figured out I had to re-create the image album in order for this to work.
4 posts, 1 answered