private static string BuildPublicUrl(MediaUrlData mediaUrlData) { IMediaUrlProvider urlProvider; if (!_mediaUrlProviders.TryGetValue(mediaUrlData.MediaStore, out urlProvider)) { urlProvider = _defaultMediaUrlProvider.Value; } if (mediaUrlData.QueryParameters.Count > 0) { var resizingOptions = ResizingOptions.Parse(mediaUrlData.QueryParameters); if (!resizingOptions.IsEmpty) { var imageResizableUrlProvider = urlProvider is IResizableImageUrlProvider ? urlProvider as IResizableImageUrlProvider : _defaultMediaUrlProvider.Value; return(imageResizableUrlProvider.GetResizedImageUrl(mediaUrlData.MediaStore, mediaUrlData.MediaId, resizingOptions)); } } return(urlProvider.GetPublicMediaUrl(mediaUrlData.MediaStore, mediaUrlData.MediaId)); }
/// <exclude /> public string GetResizedImageUrl(string storeId, Guid mediaId, ResizingOptions resizingOptions) { IMediaFile file = GetFileById(storeId, mediaId); if (file == null) { return(null); } string pathToFile = UrlUtils.Combine(file.FolderPath, file.FileName); pathToFile = RemoveForbiddenCharactersAndNormalize(pathToFile); // IIS6 doesn't have wildcard mapping by default, so removing image extension if running in "classic" app pool if (!HttpRuntime.UsingIntegratedPipeline) { int dotOffset = pathToFile.IndexOf(".", StringComparison.Ordinal); if (dotOffset >= 0) { pathToFile = pathToFile.Substring(0, dotOffset); } } string mediaStore = string.Empty; if (!storeId.Equals(DefaultMediaStore, StringComparison.InvariantCultureIgnoreCase)) { mediaStore = storeId + "/"; } var url = new UrlBuilder(UrlUtils.PublicRootPath + "/media/" + mediaStore + /* UrlUtils.CompressGuid(*/ mediaId /*)*/) { PathInfo = file.LastWriteTime != null ? "/" + GetDateTimeHash(file.LastWriteTime.Value.ToUniversalTime()) : string.Empty }; if (pathToFile.Length > 0) { url.PathInfo += pathToFile; } if (resizingOptions != null && !resizingOptions.IsEmpty) { return(url + "?" + resizingOptions); } return(url.ToString()); }
/// <summary> /// Returns a media url. /// </summary> /// <param name="keyPath">Image's KeyPath field value.</param> /// <param name="resizingOptions">The resizing options.</param> /// <returns></returns> public IHtmlString MediaUrl(string keyPath, ResizingOptions resizingOptions) { string relativeUrl = "~/media(" + keyPath + ")"; string absoluteUrl = VirtualPathUtility.ToAbsolute(relativeUrl); string queryString = resizingOptions.ToString(); if (!string.IsNullOrEmpty(queryString)) { absoluteUrl += "?" + queryString.Replace("&", "&"); } return(_helper.Raw(absoluteUrl)); }
public static bool IsLocalC1MediaWithoutResizingOptions(string relativeUrl) { if (!relativeUrl.StartsWith(MediaUrlUnprocessedInternalPrefix) && !relativeUrl.StartsWith(MediaUrlInternalPrefix) && !relativeUrl.StartsWith(MediaUrlPublicPrefix)) { return(false); } var parsedUrl = new UrlBuilder(relativeUrl); var queryParameters = parsedUrl.GetQueryParameters(); return(ResizingOptions.Parse(queryParameters).IsEmpty); }
private static string BuildPublicUrl(MediaUrlData mediaUrlData) { IMediaUrlProvider urlProvider; if (!_mediaUrlProviders.TryGetValue(mediaUrlData.MediaStore, out urlProvider)) { urlProvider = _defaultMediaUrlProvider.Value; } if (mediaUrlData.QueryParameters.Count > 0) { string mediaUrl; var resizingOptions = ResizingOptions.Parse(mediaUrlData.QueryParameters); var noneResizingOptions = mediaUrlData.QueryParameters; if (!resizingOptions.IsEmpty) { var imageResizableUrlProvider = urlProvider is IResizableImageUrlProvider ? urlProvider as IResizableImageUrlProvider : _defaultMediaUrlProvider.Value; mediaUrl = imageResizableUrlProvider.GetResizedImageUrl(mediaUrlData.MediaStore, mediaUrlData.MediaId, resizingOptions); foreach (var key in HttpUtility.ParseQueryString(resizingOptions.ToString()).AllKeys) { noneResizingOptions.Remove(key); } } else { mediaUrl = urlProvider.GetPublicMediaUrl(mediaUrlData.MediaStore, mediaUrlData.MediaId); } if (noneResizingOptions.Count > 0) { var urlBuilder = new UrlBuilder(mediaUrl); urlBuilder.AddQueryParameters(noneResizingOptions); return(urlBuilder.ToString()); } return(mediaUrl); } return(urlProvider.GetPublicMediaUrl(mediaUrlData.MediaStore, mediaUrlData.MediaId)); }
/// <summary> /// Returns a media url. /// </summary> /// <param name="image">The image file.</param> /// <param name="resizingOptions">The resizing options.</param> /// <returns></returns> public IHtmlString MediaUrl(IImageFile image, ResizingOptions resizingOptions) { return(MediaUrl(image.KeyPath, resizingOptions)); }
/// <summary> /// Returns a media url. /// </summary> /// <param name="image">The image file.</param> /// <param name="resizingOptions">The resizing options.</param> /// <returns></returns> public IHtmlString MediaUrl(DataReference <IImageFile> image, ResizingOptions resizingOptions) { return(MediaUrl((string)image.KeyValue, resizingOptions)); }