Try our conversational search powered by Generative AI!

Migrate site with images to ImageVault 4

Vote:
 

Hi,

I have this EPiServer CMS 7.5 site that is up and running, now the customer wants us to install ImageVault 4 on it. The problem I'm facing is that all the current imageproperties needs to be rewritten in my models to ImageVault-properties and when this is done, the current image is lost. Hence the customer needs to repick all images on the whole site!, we don't want that :).

So my question is if there is some trick to migrate the pictures from my current imageproperties to the new ImageVault-property?.

#89885
Aug 28, 2014 8:26
Vote:
 

Basically you need to migrate the assets from the old solution to the new ImageVault 4 database using the migration tool. 

As you have guessed you need to write some code that iterates through all you pages on the sites and calculate the new ImageVault properties from the old. 

During migration ImageVault migration tool adds some new meta data to the new images. The field "IV3_DataObjectId" is used to convert old properties to the new.

Basically the internal format of an old ImageVault property contins the id (like "url to image~id~alt text") so you extract the id and use it too lookup the image where IV3_DataObjectId has a matching value in ImageVault 4.

We had a nice demo on this at an EPiServer meetup and I'm sure you can get the slides/demo code if you reach out to Johan at ImageVault.

#89992
Aug 31, 2014 16:08
Vote:
 

I interpret the question to be about copying and/or converting 7.5 EPi mediadata and properties where those are linked into IV4 media and properties. Am I correct Joakim?

#90011
Edited, Sep 01, 2014 10:26
Vote:
 

Hi!

After migrating the ImageVault data using the migration tool the content published to EPiServer needs to be converted as well. Normally this is done by replacing the existing ImageVault 3 properties with Media or MedaiList properties in ImageVault 4 and adding a reference to the migrated file.

Below are the code example from the EPiServer meetup Fredrik was refering to:

This example assumes that you have a side-by-side installation of ImageVault 3 and 4 and that you are using PageTypeBuilder.
The page template has an ImageVaultImage property (ImageType) called "IV3Image"

Start by adding a Meda property to the page template.

[PageTypeProperty(Type = typeof(PropertyMedia))]
[PropertyMediaSettings(Height = 200, Width = 350, ResizeMode = ResizeMode.ScaleToFill)]
public virtual MediaReference IV4Image { get; set; }

To be able to set the PropertyMediaSettings you will need the following class

    internal sealed class PropertyMediaSettingsAttribute : Attribute, IUpdatePropertySettings {

        /* *******************************************************************
         *  Properties
         * *******************************************************************/
        public int Width { get; set; }
        public int Height { get; set; }
        public ResizeMode ResizeMode { get; set; }

        public void UpdateSettings(PropertyMediaSettings settings) {
            settings.Width = Width;
            settings.Height = Height;
            settings.ResizeMode = ResizeMode;
        }

        public int GetSettingsHashCode(PropertyMediaSettings settings) {
            return settings.Height + settings.Width + (int)settings.ResizeMode;
        }

        public bool OverWriteExistingSettings {
            get { return true; }
        }
    }

Then create a data object that will be used to find the matching image after migration.    

using ImageVault.Common.Data;
using ImageVault.Client.Descriptors;

namespace EPiServer.Templates.Demo.Pages {

    public class MyMediaItem : MediaItem {

        [Metadata(Name = "IV3_DataObjectId", Type = MetadataDefinitionTypes.User)]
        public int IV3Id { get; set; }
    }

}

And finally the code to populate the new Media property.

if (CurrentPage["IV3Image"] != null && CurrentPage["IV4Image"] == null) {

    // Parse IV3 property for Id
    var oldImage = IVUrlBuilder.ParseUrl(CurrentPage["IV3Image"] as String);

    // Search for corresponding Media in IV4
    var client = new Client();
    var newImage = client.Query().Where(x => x.IV3Id == oldImage.Id).SingleOrDefault();
    var media = new MediaReference {Id = newImage.Id };

    // Update EPiServer
    var pd = CurrentPage.CreateWritableClone();
    pd["IV4Image"] = media;
    DataFactory.Instance.Save(pd, SaveAction.Publish);

}

In this example this is done in Page_Load, but probably should be done in a scheduled job or similliar.

This should work for instances were the automatic resizing of images are used and the same approach could also be used for images in the free text editor.
We are working on a blog post regarding how to handle manually edited images and more.

 /Johan

#90020
Sep 01, 2014 11:11
Vote:
 

If you want to do this with EPiServer image properties you need to upload the media to ImageVault first 

http://imagevault.se/en/documentation/api-documentation/?page=csharp/examples/upload.html

and then when you got the Id of the media you can store it to the ImageVault media property using the code in the example above.

This can of course be done using a job or external program to iterate all episerver pages instead.

/Dan

#90062
Edited, Sep 01, 2014 14:58
* 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.