Copied to clipboard

Flag this post as spam?

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


  • NDDT 68 posts 240 karma points c-trib
    Oct 28, 2016 @ 11:36
    NDDT
    0

    Save into ImageCropper programmatically

    I have links to pictures which need to be saved in an ImageCropper-Field.

    Has anyone maybe done this before?

    If I insert the Link the ImageCropper just points to it but cant resize it. Can anyone provide samplecode?

    Thanks :)

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Oct 31, 2016 @ 09:43
    Warren Buckley
    1

    Hellp NDDT,
    I am not 100% sure I fully understand your question, what are you trying to achieve here?

    When you say link, what type of datatype is this?

    With some more details I am sure I can help or someone else with a few more details.

    Thanks,
    Warren

  • NDDT 68 posts 240 karma points c-trib
    Oct 31, 2016 @ 11:15
    NDDT
    0

    Its a Link in form of a String and I wanted to save the image (the link leads to) into an imagecropper. It works now.

    I just had to create a FileStream-Object of the Image and I was able to just asign it to the property.

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Oct 31, 2016 @ 11:30
    Warren Buckley
    1

    OK I am glad you solved your own problem then.

    Maybe to help others who search or come across the same problem is to post a code snippet so others can benefit from it too.

    Thanks,
    Warren

  • NDDT 68 posts 240 karma points c-trib
    Oct 31, 2016 @ 12:48
    NDDT
    100

    Of Course ;)

    IContent myDoc = \\get or create ur Doc here 
    string tempFolder = umbraco.GlobalSettings.FullpathToRoot + "//temp//"; string linkToImage = "http://somewebsite.com/mypic.jpg";
    if (!String.IsNullOrEmpty(linkToImage))
    {
        Uri imageUrl = new Uri(linkToImage);
        string filename = Path.GetFileName(imageUrl.PathAndQuery);
        webClient.DownloadFile(linkToImage, tempFolder + filename);
        FileStream fs = new FileStream(tempFolder + filename, FileMode.Open);
        myDoc.SetValue("anzeigeBild", filename, fs);
        fs.Close();
        Services.ContentService.SaveAndPublishWithStatus(myDoc);
        foreach (FileInfo file in new DirectoryInfo(tempFolder).GetFiles()) file.Delete();
    }
    

    This worked for me. It was fast enough. Maybe there is a way to do this without saving the file to disk before creating a filestream. I just had to run this once, so this was fine for me.

Please Sign in or register to post replies

Write your reply to:

Draft