Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • James 5 posts 75 karma points
    Mar 19, 2016 @ 17:52
    James
    0

    Node creation with image cropper field

    I'm successfully creating nodes through a surface controller.

    Here's how I'm populating image cropper filed and saving a node...

    contentNode.SetValue("image", @"\uploadedImages\Avatargirlface.png"); contentService.SaveAndPublish(contentNode);

    Looking in the CMS, I can see it has successfully saved the node; the image is there and so is a cropped version. Great.

    Problem is that the image src will not output on front end until I manually go the node and 'save and publish'. Src just appears empty until I do this.

    I expected this to happen automatically.

    Any ideas what I am missing please?

  • James 5 posts 75 karma points
    Mar 20, 2016 @ 18:38
    James
    0

    Just some more info in case this is not clear...

    1) Image is saved to node (image cropper field) via Content Service 2) I check content, image is present in node :-) 3) Image ought to show in view but it does not. 4) If I hit 'save and publish' in CMS , image now appears on view

    So it's like I have to save it again to get it to work. How can I get it to work without step 4?

    Please help, I've spent ages on this. Thanks.

  • James 5 posts 75 karma points
    Mar 21, 2016 @ 20:16
    James
    0

    Hello.

    Ok. I finally figured it out with a different around the houses approach. It works, not sure if it's the right way though as a newbie...

    1) Used Media Service to upload image via a Surface Controller

    2) Used Content Service to create node

    3) Store a date stamp in both the image and node

    4) In partial view macro, iterate through folder and display the image that matches the magic date stamp.

    Seems a bit long-winded - hopefully not too resource heavy. I did it this way because Media Service puts each image you upload in a separate folder, meaning you can't predict the path to file, even if you know the name.

    Also, I also couldn't find a way to rename the file so I couldn't be certain it would be unique.

    I'd imagined you would be able to save an image straight to a node, but seems not.

    Any clarifications you can give to help me clean up my act would be appreciated.

    Cheers.

  • OXEN 4 posts 75 karma points
    Oct 29, 2019 @ 18:47
    OXEN
    0
     using (var wc = new System.Net.WebClient())
     {                               
    
         byte[] bytes = wc.DownloadData(prNewswireModel.ImageUrl);
         Stream stream = new MemoryStream(bytes);
         content.SetValue(contentTypeService, "image", 
                                "dynamic_name_goes_here.jpg", stream);
          contentService.Save(content);
          var imageurl = content.GetValue("image");                                
           contentService.Save(content);
    
           var jsoncropurl = "{\"src\":\""+ imageurl + "\",\"crops\":[{\"alias\":\"574x443\",\"width\":574,\"height\":443},{\"alias\":\"274x442\",\"width\":274,\"height\":442},{\"alias\":\"374x215\",\"width\":374,\"height\":215},{\"alias\":\"393x196\",\"width\":393,\"height\":196},{\"alias\":\"372x187\",\"width\":372,\"height\":187},{\"alias\":\"288x166\",\"width\":288,\"height\":166},{\"alias\":\"465x402\",\"width\":465,\"height\":402},{\"alias\":\"343x197\",\"width\":343,\"height\":197},{\"alias\":\"145x72\",\"width\":145,\"height\":72},{\"alias\":\"528x263\",\"width\":528,\"height\":263}]}";
               content.SetValue("image", jsoncropurl);
               contentService.Save(content);
       }
    

    // My solution was the one above.

Please Sign in or register to post replies

Write your reply to:

Draft