I am trying to move media from 7.2 to 7.4, but to a new instance. so basically what i did I used the code bellow to get the structure and the details of the images in xml from the 7.2 instance.
umbraco.DataLayer.ISqlHelper SqlHelper = umbraco.BusinessLogic.Application.SqlHelper;
int mediaId = -1;
//Create an empty xmlDocument.
System.Xml.Linq.XDocument xmlDocument = new System.Xml.Linq.XDocument(
new System.Xml.Linq.XElement("Media")
);
if (mediaId == -1)
{
//If the mediaId is -1 loop through all the top media nodes.
using (umbraco.DataLayer.IRecordsReader dr = SqlHelper.ExecuteReader("Select id from umbracoNode where nodeObjectType = @type And parentId = -1 order by sortOrder",
SqlHelper.CreateParameter("@type", umbraco.cms.businesslogic.media.Media._objectType)))
{
while (dr.Read())
{
//Get the hierarchical xml from each topnode and add it to the xmlDocument.
xmlDocument.Root.Add(System.Xml.Linq.XElement.Parse(umbraco.library.GetMedia(dr.GetInt("id"), true).Current.OuterXml));
}
}
}
else
{
//Get the hierarchical xml from the media id and add it to the xmlDocument.
xmlDocument.Root.Add(System.Xml.Linq.XElement.Parse(umbraco.library.GetMedia(mediaId, true).Current.OuterXml));
}
And it works just fine, but now i am trying to push things to the new instance of media I know i can create folders and images using the media service like below.
var mediaImage = mediaService.CreateMedia("test4", 1152, "Image");
mediaImage.SetValue("umbracoFile", test, fileStream);
mediaService.Save(mediaImage);
But the problem is i have loads of cropped images but i have no idea how to add them below is an xml sample
can you please explain to me how to set the cropper to the image. your code set new value but i can't understand what should i do with the return value.
I have not tested this since I am making a couple of presumptions on how your project is set up.
Looking at the xml you posted, I presume that you have a Media Type with alias "ImageCropper" that has the same properties as Media Type "Image" but renders them differently.
I have no idea how to save a filestream to disk using the umbraco path without calling mediaImage.SetValue("umbracoFile", test, fileStream);
SO...
Create the image like normal but with the correct media type
var mediaImage = mediaService.CreateMedia("test4", 1152, "ImageCropper");
mediaImage.SetValue("umbracoFile", test, fileStream);
mediaService.Save(mediaImage);
This will create a media item and upload the file in the correct folder.
Next, get the crop representation of that saved file, change the property, and save the media item again.
I get this error No MediaType matching the passed in Alias: 'ImageCropper' was found which i have no idea why. i know File and Image aliases are fine but when i try ImageCropper it fail.
Because you probably still have to create the media type in your new instance. Look in the developer section on your old instance for the media type if my presumptions are right, it should be there.
I just checked the developer section and the type is there Umbraco.ImageCropper . I am not sure what i am doing any idea where should i look for more clues.
Yes but without the umbraco. Just the imagecropper i will try the whole word tomorrow and tell you how it goes. And i will pass you some of thr code. Maybe i am doing something obviously wrong.
Upload Image and cropper info Progrmatically
Hi Guys,
I am trying to move media from 7.2 to 7.4, but to a new instance. so basically what i did I used the code bellow to get the structure and the details of the images in xml from the 7.2 instance.
And it works just fine, but now i am trying to push things to the new instance of media I know i can create folders and images using the media service like below.
But the problem is i have loads of cropped images but i have no idea how to add them below is an xml sample
as you can see the nodeTypeAlias is ImageCropper so chow can i upload these images or insert the cropper details in.
is it possible ?
thank you in advance
hyde
I do not have much time right now, but maybe this bit will help you along. If you have any more questions I will reply later.
Set the string representation of the result as the value of your propertie.
Hello sven thanks for your reply
can you please explain to me how to set the cropper to the image. your code set new value but i can't understand what should i do with the return value.
thank you
hyde
I have not tested this since I am making a couple of presumptions on how your project is set up.
Looking at the xml you posted, I presume that you have a Media Type with alias "ImageCropper" that has the same properties as Media Type "Image" but renders them differently.
I have no idea how to save a filestream to disk using the umbraco path without calling
mediaImage.SetValue("umbracoFile", test, fileStream);
SO...
Create the image like normal but with the correct media type
This will create a media item and upload the file in the correct folder.
Next, get the crop representation of that saved file, change the property, and save the media item again.
Note: I updated my previous post to reflect the usage of the code here.
I get this error
No MediaType matching the passed in Alias: 'ImageCropper' was found
which i have no idea why. i know File and Image aliases are fine but when i try ImageCropper it fail.any ideas ?
Because you probably still have to create the media type in your new instance. Look in the developer section on your old instance for the media type if my presumptions are right, it should be there.
I just checked the developer section and the type is there
Umbraco.ImageCropper
. I am not sure what i am doing any idea where should i look for more clues.thank you
And you used the alias of that type in the media creation?
Hi Sven,
still not working getting the same error. anymore ideas ?!!!
My apologies you are correct. i was missing the type in the media types. thank you for the help.
Glad to hear you got it to work.
Yes but without the umbraco. Just the imagecropper i will try the whole word tomorrow and tell you how it goes. And i will pass you some of thr code. Maybe i am doing something obviously wrong.
Thank you
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.