Copied to clipboard

Flag this post as spam?

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


  • Lee Surr 10 posts 132 karma points
    Aug 28, 2018 @ 16:41
    Lee Surr
    0

    Error on MediaPicker2 using Set Value

    Hi,

    Sorry I'm quite new to using Umbraco the MVC way in Viusal Studio and this is my first post on the Umbraco forum.

    I can get the image to upload to the media library in the correct folder and set its value to the mediaPicker2 property editor i have set up. However the issue i get is in the content editor I'm receiving the following error.enter image description here

    The image appears in the front end and the media library absolutely fine but doesn't display correctly in the doc type.

    Any help would be much appreciated.

    My code in the controller is:

                var mediaService = Services.MediaService;
    
                if (model.FundImages.HasFiles() && model.FundImages.ContainsImages())
                {
                    var imagesProperty = Fund.GetModelPropertyType(d => d.FundImage);
                    var folderId = content.GetValue<int>(imagesProperty.PropertyTypeAlias);
    
                    if (folderId <= 0)
                    {
                        var folder = mediaService.CreateMedia(fundName, 1277, Folder.ModelTypeAlias);
                        mediaService.Save(folder);
                        folderId = folder.Id;
                        content.SetValue(imagesProperty.PropertyTypeAlias, folderId);
                    }
    
                    foreach (var file in model.FundImages)
                    {
                        if (file.IsImage())
                        {
                            // Process Files and save them in the media libary
                            var mediaImage = mediaService.CreateMedia(file.FileName, folderId, Image.ModelTypeAlias);
                            var umbracoFileProperty = Image.GetModelPropertyType(i => i.UmbracoFile);
                            mediaImage.SetValue(umbracoFileProperty.PropertyTypeAlias, file);
                            mediaService.Save(mediaImage);
                            // attach image to umbraco property
    
                            //var udi = Udi.Create(Constants.UdiEntityType.Media, mediaImage.Key);
                            //newFund.SetValue("fundImage", udi.ToString());
                            newFund.SetValue("fundImage", "umb://media/" + mediaImage.Key);
                        }
                    }
                }
    
                // remember to save
                _contentServices.Save(newFund);
    
                // publish
                _contentServices.Publish(newFund);
    
  • Rami H 13 posts 141 karma points
    Aug 28, 2018 @ 23:49
    Rami H
    0

    Hi Lee,

    Which version of Umbraco are you using? There's a known issue about this sort of thing in V7.7.3. There is a JS fix posted there that you can use to see if that helps. Let us know how it goes.

  • Lee Surr 10 posts 132 karma points
    Aug 29, 2018 @ 08:04
    Lee Surr
    0

    Hi Rami,

    I'm currently using 7.12.1. I'll give this a try and let you know how i get on. Thanks for getting back to me.

  • Rami H 13 posts 141 karma points
    Aug 29, 2018 @ 13:40
    Rami H
    0

    Hey Lee,

    That error should be fixed in 7.12. If you updated recently, you may want to try resetting ClientDependency or rename the folder in App_Data/Temp. I wouldn't trust copying that script over as you're current version is way past that particular fix.

    Another thought, I'm not totally 100% sure on, but could be worth a try. When you're saving your content node you have:

    // remember to save
            _contentServices.Save(newFund);
    
            // publish
            _contentServices.Publish(newFund);
    

    Try the newer methods:

    _contentServices.SaveAndPublishWithStatus(newFund);
    

    It might kick start some event based dependency, I'm not totally sure though. Worth a shot.

    Let us know how it goes!

  • Lee Surr 10 posts 132 karma points
    Aug 29, 2018 @ 19:04
    Lee Surr
    0

    Hey Rami,

    Thanks for the advice. I'm afraid still no luck.I have reset the ClientDependency folder and changed to the newer save and publish method. I'm still getting the same error.

  • Lee Surr 10 posts 132 karma points
    Aug 29, 2018 @ 19:12
    Lee Surr
    101

    Manage to fix it.

    Instead of:

    newFund.SetValue("fundImage", "umb://media/" + mediaImage.Key);
    

    I used:

    newFund.SetValue("fundImage", mediaImage.GetUdi().ToString());
    

    Thanks for your help Rami.

  • Rami H 13 posts 141 karma points
    Aug 29, 2018 @ 20:27
    Rami H
    0

    Oh nice! Yeah that makes sense, good work!

Please Sign in or register to post replies

Write your reply to:

Draft