Umbraco以编程方式上传图片和剪贴画信息

时间:2016-09-16 10:27:31

标签: c# asp.net-mvc umbraco umbraco7

我正在尝试将介质从7.2移动到7.4,但是要移植到新实例。基本上我做了什么我用下面的代码从7.2实例获取xml中图像的结构和细节。

   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));
}

它工作正常,但现在我正在努力将事情推向新的媒体实例,我知道我可以使用下面的媒体服务创建文件夹和图像。

var mediaImage = mediaService.CreateMedia("test4", 1152, "Image");
mediaImage.SetValue("umbracoFile", test, fileStream);
mediaService.Save(mediaImage);

但问题是我有大量的裁剪图像,但我不知道如何在下面添加它们是一个xml样本

 <Folder id="1126" parentID="-1" level="1" creatorID="0" sortOrder="0" createDate="2014-09-29T16:22:37" updateDate="2015-05-12T16:27:28" nodeName="Images" urlName="images" path="-1,1126" isDoc="" nodeType="1031" writerName="  Admin" writerID="0" version="3c3ccf09-e001-4fe5-8b1c-75a2da18d40c" template="0" nodeTypeAlias="Folder">
    <ImageCropper id="13081" parentID="1126" level="5" creatorID="0" sortOrder="4" createDate="2015-10-26T16:21:23" updateDate="2016-02-22T10:32:32" nodeName="Bla bla" urlName="test" path="-1,1126,1235,1378,1401,13081" isDoc="" nodeType="12390" writerName="  Admin" writerID="0" version="5860627c-f0f9-49e9-8114-3d52d3f93f03" template="0" nodeTypeAlias="ImageCropper">
              <umbracoHeight>200</umbracoHeight>
              <umbracoBytes>54244</umbracoBytes>
              <umbracoExtension>jpg</umbracoExtension>
              <umbracoFile>{ "focalPoint": { "left": 0.5, "top": 0.5 }, "src": "/media/392270/cropped-test.jpg", "crops": [ { "alias": "CTA Image", "width": 542, "height": 364, "coordinates": { "x1": 0.038364212277255755, "y1": 0, "x2": 0.0984410114844898, "y2": 0 } }, { "alias": "Wide CTA Image", "width": 960, "height": 320 }, { "alias": "Sidebar Image", "width": 400, "height": 333 }, { "alias": "Home Featured Videos Image", "width": 300, "height": 200, "coordinates": { "x1": 0.057971014492753624, "y1": 0, "x2": 0.072463768115942032, "y2": 0 } }, { "alias": "Support   Box Image", "width": 670, "height": 107 }, { "alias": "Council Landing Page Image", "width": 166, "height": 173 }, { "alias": "Trainee Committee Image", "width": 166, "height": 173 }, { "alias": "Masthead Image", "width": 1280, "height": 200 } ] }</umbracoFile>
           </ImageCropper>
           <ImageCropper id="13082" parentID="1401" level="5" creatorID="0" sortOrder="5" createDate="2015-10-26T16:26:25" updateDate="2016-02-22T10:32:51" nodeName="Getting into Medical School" urlName="getting-into-medical-school" path="-1,1126,1235,1378,1401,13082" isDoc="" nodeType="12390" writerName="  Admin" writerID="0" version="8fd4760d-fde4-42ff-9073-2d4170bd5fdf" template="0" nodeTypeAlias="ImageCropper">
              <umbracoHeight>313</umbracoHeight>
              <umbracoBytes>259343</umbracoBytes>
              <umbracoExtension>jpg</umbracoExtension>
              <umbracoFile>{ "focalPoint": { "left": 0.5, "top": 0.5 }, "src": "/media/392271/gh_rcs_250715_urgent_28-v2.jpg", "crops": [ { "alias": "CTA Image", "width": 542, "height": 364, "coordinates": { "x1": 0.042627479228088981, "y1": 0, "x2": 0.24691453363709465, "y2": 0 } }, { "alias": "Wide CTA Image", "width": 960, "height": 320 }, { "alias": "Sidebar Image", "width": 400, "height": 333 }, { "alias": "Home Featured Videos Image", "width": 300, "height": 200, "coordinates": { "x1": 0.042942073170731711, "y1": 0, "x2": 0.24135670731707312, "y2": 0 } }, { "alias": "Support   Box Image", "width": 670, "height": 107 }, { "alias": "Council Landing Page Image", "width": 166, "height": 173 }, { "alias": "Trainee Committee Image", "width": 166, "height": 173 }, { "alias": "Masthead Image", "width": 1280, "height": 200 } ] }</umbracoFile>
           </ImageCropper>

你可以看到nodeTypeAlias是ImageCropper所以我可以上传这些图像或插入剪裁器细节。

有可能吗?

0 个答案:

没有答案