Try our conversational search powered by Generative AI!

Creating new Image(Data) from other Image type

Nat
Nat
Vote:
 

We are trying to migrate some content from our v11 cms to our v12 instance.

This has proved pretty painful, as the pages/blocks/media types have changed considerably. 
Currently we have a number of converters which take an old type and create and save a new type, not really any problems there.

The paln is to take a start page and convert that, working around all its properties - creating any content which any of its properties reference (blocks/other pages/images etc) - save the old references along with the new ones to avoid creating them twice, then start working down the list of child pages

However, when it comes to content references and more specifically Images things appear to be a bit more complicated.
if I have an old ImageFileOld type say - which inherits from ImageData and looks like so:

public class ImageFileOld : ImageData
    {
        public virtual string Copyright { get; set; }

        public virtual string AltText { get; set; }

        public virtual int Height { get; set; }

        public virtual int Width { get; set; }

        public virtual int FileSizeInBytes { get; set; }
    }

which we would like to 'convert' to a new type:

public class ImageFile : ImageData
  {
    [Required]
    public virtual string AltText { get; set; }

    public virtual string HorizontalFocus { get; set; }

    public virtual string VerticalFocus { get; set; }
}

We were hoping that something along these lines would work

    var oldImage = somePageInstance.ImageContentReferenceProperty; 
    var newImage = ContentRepository.GetDefault<ImageFile>(oldImage.ParentLink)
    newImage.AltText = oldImage.AltText ?? newImage.Name;
    newImage.BinaryData = oldImage.BinaryData;
    newImage.Thumbnail = oldImage.Thumbnail;
    newImage.ParentLink = oldImage.ParentLink;
    newImage.RouteSegment = AddVersionToImageRouteSegment(oldImage.RouteSegment); //cant use the same routesegment as its being saved in the same folder
    newImage.HorizontalFocus = ImageHorizontalFocusMappingsSelectionFactory.DefaultValue;
    newImage.VerticalFocus = ImageVerticalFocusMappingsSelectionFactory.DefaultValue;

    ContentRepository.Save(newImage, SaveAction.Publish, AccessLevel.NoAccess);

however, this doesnt seem to be enough. pretty sure we have set all the properties we can. Do I instead need to do something ddirectly with the blobprovider or ..??
the image is created, but its not viewable 

#309902
Oct 03, 2023 15:06
Vote:
 

 I think some work may be needed to Create the blob for the new image, based off the binary data of the old image, for this to work and to see the viewable image image. This article may be useful https://world.optimizely.com/forum/developer-forum/Developer-to-developer/Thread-Container/2016/6/how-to-upload-images-progammatically-for-a-page/

#312694
Nov 17, 2023 17:41
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.