Surendra Sharma

Surendra Sharma

Search This Blog

Thursday, June 22, 2017

How to download Sitecore media library item on client browser programmatically


Sitecore Media Item Download
Sitecore Media Item Download


One of my friend struggling for downloading PDF file from Sitecore media library on client browser
. So I thought to write a code on the same.


Below code can force any media library item to be downloaded on client browser.

private void DownloadMediaLibraryItem()
{
    //Get Media Item
    var mediaItem = Sitecore.Data.Database.GetDatabase("master").GetItem(new ID("{5D8B8B5B-BD43-4F8E-B1B5-EACA7D78F0DE}"));
    var media = Sitecore.Resources.Media.MediaManager.GetMedia(mediaItem);

    //Get Media Stream in buffer
    var mediaStream = media.GetStream();
    byte[] buffer = new byte[(int)mediaStream.Length];
    mediaStream.Stream.Read(buffer, 0, (int)mediaStream.Length);

    //Send response to browser
    System.Web.HttpContext.Current.Response.Clear();
    System.Web.HttpContext.Current.Response.ClearContent();
    System.Web.HttpContext.Current.Response.ClearHeaders();
    System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
    System.Web.HttpContext.Current.Response.AddHeader("Content-Length", buffer.Length.ToString());
    System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + mediaItem.Name + ".pdf");
    System.Web.HttpContext.Current.Response.BinaryWrite(buffer);
    System.Web.HttpContext.Current.Response.Flush();
    System.Web.HttpContext.Current.Response.End();
}

I hope you like this Sitecore article. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)
 
Please leave your comments or share this code if it’s useful for you.

Sunday, June 18, 2017

How to replace Brightcove Adobe Flash player with HTML5 player in Sitecore


Use HTL5 player of Brightcove in Sitecore
Use HTL5 player of Brightcove in Sitecore

One of our site is using Brightcove Adobe Flash player which we have to replace with new Brightcove player which support HTML5. 
 
Follow below steps to configure Brightcove Video Cloud running as an HTML5 player

  • Step 1: Please navigate to section "Brightcove.StorageService" and change the "baseUrl" param value with your website URL and also set the "ContentDatabaseName" and "PublishDatabaseName" param values from Sitecore.MediaFramework.Services.Brightcove.Extended.config.disabled config file.
  • Step 2: Enable the config file named as "Sitecore.MediaFramework.Services.Brightcove.Extended.config.disabled".
  • Step 3: We need to add mimetype "text/vtt" with extension (.vtt) in IIS.
  • Add new player at “/sitecore/media library/Media Framework/Accounts/Default/Players” with unique player id.
  • Update “Default Video Player” field and “Default Playlist Player” to new player at “/sitecore/media library/Media Framework/Accounts/Default/Settings
  • Include “<script src="//players.brightcove.net/<licence id>/<Player_Id>_default/index.min.js"></script>” on all pages where you want to show Brightcove videos.
  • Publish all the Brightcove items
  • Test the page on which Brightcove videos are rendering.
I hope you like this Sitecore article. Stay tuned for more Sitecore related articles.

Till that happy Sitecoring :)

Please leave your comments or share this article if it’s useful for you.