So, I am creating a content importer to pull content in from an external source into sitecore.
I create an image like so:
MediaCreatorOptions options = new MediaCreatorOptions();
options.FileBased = false;
options.IncludeExtensionInItemName = false;
options.KeepExisting = false;
options.Versioned = false;
options.Destination = sitecorePath + mediaItemName;
options.Database = Factory.GetDatabase("master");
using (new SecurityDisabler())
{
MediaCreator creator = new MediaCreator();
global::Sitecore.Data.Items.MediaItem mediaItem = creator.CreateFromFile(fileName, options);
}
This does happily create the media item in sitecore and I can browse it in the media library.
The next step is to create the actual content page. I do stuff like this:
var sitecoreModel = new NewsArticleForImport();
sitecoreModel.Summary = articleContent.Summary;
sitecoreModel.Headline = articleContent.Headline;
using (new SecurityDisabler()) {
masterService.Create(newsRootItem, sitecoreModel);
}
And this works fine.
The problem comes when I want to assign my image to my page. The question therefore is, how do I convert a MediaItem to a Glass.Mapper.Sc.Fields.Image, so I can assign it to my page?