1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Download filenames when using Amazon S3

Download filenames when using Amazon S3

2 posts, 0 answered
  1. Bryan
    Bryan avatar
    14 posts
    Registered:
    20 Aug 2008
    11 Feb 2010
    Link to this post
    Hello,

    Is there a way to have the friendly filename display when downloading a file that was uploaded to the Amazon S3? For example if I upload a file called ExcelFile.xlsx to a document library and place this document on a page the download filename will use the S3 name instead of the uploaded filename, for example e8e0ffe6eff94071af75941e46faa683.xlsx.

    Thanks!
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    15 Feb 2010
    Link to this post
    Hi Bryan,

    You need to create a custom class that derives from AmazonProvider and implement a new method to save the content item where you set your custom url

    sample code

    public class AmazonCustomProvider : AmazonProvider
    {
        public AmazonCustomProvider()
        {
             
        }
     
        protected override void OnExecuting(Telerik.ExecutingEventArgs args, bool fireEvents)
        {
            if (!args.Cancel)
            {
                IContent item = args.CommandArguments as IContent;
                if (item != null && args.CommandName == "CreateContent")
                {
                    ILibrary library = GetLibrary(item.ParentID);
                    StorageManager.Init(library.TypeName);
                    SaveContentToExternal(item, library);
     
                }
                else
                {
                    base.OnExecuting(args, fireEvents);
                }
            }
        }
     
        protected virtual void SaveContentToExternal(IContent item, ILibrary library)
        {
            if (item.Content is byte[])
            {
                byte[] content = (byte[])item.Content;
                string url = StorageManager.Create(library.TypeName, item.ID, content, item.MimeType);
     
                // map the url here
                 
            }
        }
     
        private string contentUrl = string.Empty;
     
     
     
    }

    Note that by default the itemContent is set to the contentUrl. Then there is an AmazonS3 Handler that checks the url, so you need to override its logic as well. You should create a custom hanlder that inherits from S3StorageHandler. Override ProcessRequest. Get the content item and set the contentUrl

    string contentUrl = string.Empty;
    IContent contentItem = ContentUrlRewriterService.Instance.GetContentItem(path);
     
    ....
       ....
    contentUrl = SET YOUR VALUE HERE;
     
    context.Response.Redirect(contentUrl, true);


    Kind regards,
    Ivan Dimitrov
    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.
2 posts, 0 answered