Copied to clipboard

Flag this post as spam?

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


  • M N 125 posts 212 karma points
    Nov 16, 2016 @ 17:31
    M N
    0

    Absolute Image URL or Multiple Delimited URLs Imported as Media Picker or Multiple Media Picker

    Hi Richard,

    Just thought I would post this here, in its proper home since it's fresh in my mind.

    Would it be possible to add 2 new Column Types -> Property Editors for Media Picker & Multiple Media Picker? I had one project where I ended up using CMS Import and created 2 fields for Feature & Gallery (text). They held the URL(s) for the absolute location to the media. Then once your CMS Import finished, I wrote a script that went back through those nodes and physically downloaded, pushed to media area, and assigned them to actual Media Picker and Multiple Media Picker(gallery)

    I'm going to drop a bit of code in for it here, in case anyone needs it, and to save you some time if you agree this feature would be useful.. In my mind it would be a huge time saver. Images are always the time suck :) Below is crude of course, was just a quick script to save me from manually uploading a couple hundred images manually.

    var _mediaService = ApplicationContext.Current.Services.MediaService;
    
    //need a folder to create these.. Could create a new one in CMS Import perhaps but I was passing the ID in directly. 
    IMedia topmediafolder = _mediaService.GetById(umediafolderid);
    
    //simple upload - removed my loop for brevity, but given a basic IContent node.. 
    
    IContent node  = use_umbracoContentService_To_Get_This_Node;
    
    string imgUrl = "http://pathtotheimagefile.jpg"
    string pathToTempLocal = "the raw file path to store your image temporarily"
    
    (new WebClient()).DownloadFile(imgUrl, pathToTempLocal);  //download it
    var media = _mediaService.CreateMedia(filename, topmediafolder.Id, "Image");
    
    FileStream s = new FileStream(pathToTempLocal , FileMode.Open); // could possibly just bypass the storing of the image temporarily
    media.SetValue("umbracoFile", Path.GetFileName(pathToTempLocal), s);    
    s.Close();
    _mediaService.Save(media);
    
    node.setValue("thealias_ofthe_mediapicker", media.Id.ToString());
    _contentService.Save(node);
    

    Thanks for your consideration, good time savings with CMS Import regardless.

    Cheers! -Marc

  • Richard Soeteman 4035 posts 12842 karma points MVP
    Jan 30, 2017 @ 10:59
    Richard Soeteman
    0

    HI Marc,

    Sorry for delay in response. You can use absolute image url's You can specify in the settings that you need to parse those domains. Then CMSiMport will convert the http url's to relative paths Only thing is that you need to download files first. I've done that because I don't want to be invlolved in copyright issues.

    Hope this answers your question.

    Best,

    Richard

Please Sign in or register to post replies

Write your reply to:

Draft