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 03, 2015 @ 16:52
    Terry Clancy
    0

    Need help to create a "Media" Item to access a Thumbnail already created by the Umbraco MediaService

    Dear Umbraco Folk,

    I am using the following code to to create a Umbraco Media Item of type "Image":

    var ms = ApplicationContext.Current.Services.MediaService;
    
    .//  Create the "empty" Image definition as an umbraco Media node
    var newImage = ms.CreateMedia(imageFileName, tTImagesFolderID, "Image");
    .ms.Save(newImage);
    .imageID = newImage.Id;   // Capture the Image ID
    
    //  Now convert relative web path to physical path to on disk file
    string physicalImagePath = System.Web.HttpContext.Current.Server.MapPath(imageSourcePathPrimaryString);
    // Now open a "FileStream" to that file on the physical hard disk
    System.IO.FileStream imageFileStream = new System.IO.FileStream(physicalImagePath, FileMode.Open);
    string physicalImageFileName = imageFileStream.Name;
    
    // Now use SetValue to populate the previosuly "empty" Image definition / umbraco Media node with the real file and it's associated properties
    newImage.SetValue("umbracoFile", imageFileName, imageFileStream);
    ms.Save(newImage);  // Must save !!
    imageFileStream.Close();  // Tidy up
    

    This creates a Media Item with the ID "imageID" providing access to the primary image "box_product.jpg"

    It also creates Thumbnails along with the original image a "numbered" folder in the /Media/ folder. That folder contains three images like the following:

    box_product.jpg
    box_product_big-thumb.jpg
    box_product_thumb.jpg
    

    What is the best way to create an Umbraco Media Item to access boxproductthumb.jpg (preferably using the existing Thumbnail rather than creating a new "numbered" folder in the /Media/ folder).?

    Note that I need to access the thumnail via a Umbraco Media Item because I am using uCommerce and the uCommerce "Product" Class has the following properties:

    product.PrimaryImageMediaId;
    product.ThumbnailImageMediaId
    

    I need to pupulate these with Media Item IDs.

    Thanks

    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