Copied to clipboard

Flag this post as spam?

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


  • Pawan Singh 2 posts 72 karma points
    Mar 15, 2019 @ 13:34
    Pawan Singh
    0

    Image not showing in mediaSection in Back Office

    I'm exploring umbraco 8 latest version.

    I'm trying to create new Image media within surfaceController. My problem is code executes successfully but it doesn't create image in media section.

    public class ContactFormController : SurfaceController
    {
        // GET: Tour
        [HttpPost]
        public ActionResult Submit(TourViewModel model, HttpPostedFileBase file)
        { 
                var fileName = Path.GetFileName(file.FileName);
                string imgPath = @"Path of image file aka TestImage.jpg";
    
                var ms = Services.MediaService;
    
                using (var file1 = new FileStream(imgPath, FileMode.Open))
                {
                    var parent = ms.GetRootMedia().FirstOrDefault(); // or -1 for root media object
                    var media = ms.CreateMedia("TestImage", parent, Constants.Conventions.MediaTypes.Image);
    
                  media.SetValue(Constants.Conventions.Media.File, file1); // save image inside folder
                    var mediaSaved = ms.Save(media);
                 }
    
           return RedirectToCurrentUmbracoPage();
        }
    }  
    

    Here is output: enter image description here

    Can anyone suggest why image is not loading in mediaSection ?

Please Sign in or register to post replies

Write your reply to:

Draft