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.
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);
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.
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);
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.
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.
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:
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.
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.
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:
Try the newer methods:
It might kick start some event based dependency, I'm not totally sure though. Worth a shot.
Let us know how it goes!
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.
Manage to fix it.
Instead of:
I used:
Thanks for your help Rami.
Oh nice! Yeah that makes sense, good work!
is working on a reply...