Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
------------FIXED------------------
I have fixed the problem, should have used media.GetUdi().ToString()
Hi
Has anyone managed to add an image via the API when using nested content?
My code is below, but the problem I have is I get a message saying the image is trashed, but below that is the image.
I have also attached the image.
Code for adding the image to media
public string ReturnSerializedJsonMediaObject(string excelColumn, string ncContentTypeAlias, string pathToExtractZipFile) { try { if (!string.IsNullOrEmpty(excelColumn)) { string[] splitExcelColumn = excelColumn.Split(';'); var nestedContentHelpers = new List<Dictionary<string, string>>(); foreach (var columnData in splitExcelColumn) { string[] splitHeaderAndBodyText = columnData.Split(','); Guid nestedContentKey = Guid.NewGuid(); string retrieveImage = Directory.EnumerateFiles(pathToExtractZipFile, splitHeaderAndBodyText[0], SearchOption.AllDirectories).First(); using (Stream stream = System.IO.File.OpenRead(retrieveImage)) { string imageExtension = Path.GetExtension(retrieveImage); IMedia media = _iMediaService.CreateMediaWithIdentity(nestedContentKey.ToString(), -1, "Image"); media.SetValue(_iContentTypeBaseServiceProvider, Constants.Conventions.Media.File, $"{nestedContentKey.ToString()}{imageExtension}", stream); _iMediaService.Save(media); nestedContentHelpers.Add(new Dictionary<string, string>() { {"key", nestedContentKey.ToString()}, {"name", splitHeaderAndBodyText[0]}, {"ncContentTypeAlias", ncContentTypeAlias}, {"image", media.Path}, {"imageAltText", splitHeaderAndBodyText[1]}, }); } } return JsonConvert.SerializeObject(nestedContentHelpers); } return string.Empty; } catch (Exception e) { Current.Logger.Error(System.Reflection.MethodBase.GetCurrentMethod().GetType(), $"Error adding Nested Content {e}", e); return string.Empty; } }
Code for adding content which is a foreach loop
var nestedContentImage = _iNestedContentMediaPropertiesHelper.ReturnSerializedJsonMediaObject(images, "nestedImagesDocType", pathToExtractZipFile); content.SetValue("images", nestedContentImage); _iContentService.SaveAndPublish(content);
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Add image to Nested Content via API in class library
------------FIXED------------------
I have fixed the problem, should have used media.GetUdi().ToString()
Hi
Has anyone managed to add an image via the API when using nested content?
My code is below, but the problem I have is I get a message saying the image is trashed, but below that is the image.
I have also attached the image.
Code for adding the image to media
Code for adding content which is a foreach loop
is working on a reply...