Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Terry Clancy 204 posts 941 karma points
    Sep 02, 2015 @ 08:07
    Terry Clancy
    0

    Empty Image problem using MeidaService to programaticaly create and Umbraco Media Image

    Dear Umbraco folk,

    The following code is working to create and "empty" image node in Umbraco BackOffice / Media section

    var ms = ApplicationContext.Current.Services.MediaService;
        var newImage = ms.CreateMedia(imageSourcePathPrimaryString, tTImagesFolderID, "Image");
        ms.Save(newImage);
    

    However - Then I am trying to "populate" that "empty" image node with an image and properties. To do this I am trying to use the following code:

    imageSourcePathPrimaryString = "/images/microsoft/catalog/Box_Microsoft.jpg";
        string physicalImagePath = System.Web.HttpContext.Current.Server.MapPath(imageSourcePathPrimaryString);
        System.IO.FileStream imageFileStream = new System.IO.FileStream (physicalImagePath, FileMode.Open);
        string imageFileName = imageFileStream.Name;
        newImage.SetValue("umbracoFile", imageFileName, imageFileStream);
    

    But the image remains "empty" with no image to be seen and not Width, Height, Size or Type properties set.

    Am I approaching this the right way ? Can anyone see what I might be doing wrong ?

    Thanks all.

    Terry Clancy ClanceZ

  • Terry Clancy 204 posts 941 karma points
    Sep 02, 2015 @ 08:30
    Terry Clancy
    100

    Never mind !

    All I needed was a:

    ms.Save(newImage);
    

    at the end of the code above - doh !!

    Thanks anyway

    Terry Clancy ClanceZ

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies