RadEditor Image Urls & Amazon S3

3 posts, 1 answers
  1. James
    James avatar
    7 posts
    Member since:
    Sep 2007

    Posted 14 Feb 2012 Link to this post

    I'm using the RadEditor with a ContentTypeProvider that uploads images to the Amazon S3 service. That works great, but the imageManager sets the src of the image as src='S3FileSystemHandler.ashx?path=yourFolder/yourImage.jpg'. I'd rather not have the ashx page handling the images, and would prefer the src just be src='http://s3.amazonaws.com/yourBucket/yourFolder/yourImage.jpg'. Is this possible? Is there a reason I'm missing to set the src to include the ashx page and have the ashx page handle the images rather than just hitting the image directly?

    Thanks for any help.
    Jim
  2. Answer
    Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 17 Feb 2012 Link to this post

    Hi Jim,

    The path of the image inserted by ImageManager dialog comes from the URL parameter of the FileItem. In order to achieve the required result, you need to modify the GetFiles() method of the content provider and set the direct path to the image to the URL parameter, e.g.:
    private FileItem[] GetFiles(string realDirectoryPath)
    {
        List<FileItem> filesResult = new List<FileItem>();
        List<XmlNode> responseResult = ListBucket(realDirectoryPath);
        foreach (XmlNode content in responseResult)
        {
            string key = GetKeyNode(content).InnerText;
            if (!key.EndsWith("_$folder$"))
            {
                // This is a file, not a folder
                string size = GetSizeNode(content).InnerText;
                string url = HttpUtility.UrlEncode(key);
                string fileName = VirtualPathUtility.GetFileName("/" + key);
     
                FileItem fileItem = new FileItem(fileName, VirtualPathUtility.GetExtension(key), int.Parse(size), string.Empty, url, string.Empty, GetPermissions(key));
     
                filesResult.Add(fileItem);
            }
        }
     
        return filesResult.ToArray();
    }

    The usage of a Handler in the content provider is required in case where the bucket is not public or you need do not want to expose the real image URL.

    Regards,
    Dobromir
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. James
    James avatar
    7 posts
    Member since:
    Sep 2007

    Posted 21 Feb 2012 Link to this post

    Perfect. Thanks Dobromir, that's just what I needed.
Back to Top