Last active
October 7, 2016 08:57
-
-
Save trnktms/7cb0286218a51341d39c649800013096 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using Sitecore.Data.Items; | |
using Sitecore.Resources.Media; | |
using Sitecore.SharedSource.DataImporter.Mappings.Fields; | |
using Sitecore.SharedSource.DataImporter.Providers; | |
namespace Sitecore.SharedSource.DataImporter.Mappings.Fields | |
{ | |
public class ToMedia : ToText | |
{ | |
public ToMedia(Item i) | |
: base(i) | |
{} | |
public override void FillField(BaseDataMap map, ref Item newItem, string importValue) | |
{ | |
var bytes = Convert.FromBase64String(importValue); | |
var media = MediaManager.GetMedia(newItem); | |
// here upload the picture as a .jpg | |
media.SetStream(new MemoryStream(bytes, false), "jpg"); | |
// it's needed to make it editable after SetStream becauase it closes the edit context | |
if (!newItem.Editing.IsEditing) | |
{ | |
newItem.Editing.BeginEdit(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment