Copied to clipboard

Flag this post as spam?

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


  • Chris C 43 posts 184 karma points
    Nov 30, 2018 @ 02:00
    Chris C
    0

    Create matching content when you upload media

    In the backend, is there a way to programmatically / automatically create content nodes when you upload media?

    Basically I would like to auto-create a bunch of blog post content nodes (with matching titles), when I upload media.

  • Chris C 43 posts 184 karma points
    Dec 01, 2018 @ 22:03
    Chris C
    0

    Has anyone tried to program something like this for the back end?

  • Craig100 1136 posts 2523 karma points c-trib
    Dec 03, 2018 @ 21:27
    Craig100
    1

    Hi Chris,

    I did something recently using the ContentService and MediaService to import content and related media. See them both here for starters: https://our.umbraco.com/Documentation/Reference/Management/Services/

    Then: https://our.umbraco.com/documentation/reference/events/contentservice-events

    and

    https://our.umbraco.com/documentation/reference/events/mediaservice-events

    and

    http://jamessouth.me/archive/experiments-with-umbracos-icontentservice/

    There are other resources and examples around which, with a little imagination, should get you where you want to be :)

    If you're lucky enough to be importing into known Media folders, I'd stream the media in, save it, inspect the relevant Media folder for mediaItem ID's, then save the list to use in a ContentItem's mediaPicker (which just requires a comma separated list of ID's). You create the ContentItem right there.

    Hope this helps.

    Craig

  • Chris C 43 posts 184 karma points
    Dec 04, 2018 @ 05:53
    Chris C
    0

    Thanks, I can see how those events can be used to programmatically deal with content and media items.

    Forgive my ignorance though... Where and how do I tie into these? Can I use a datatype/macro/contentType in the backend to run custom code?

    I remember in a previous version of Umbraco, there was a site template you could install where media uploads had a checkbox that said something like "auto-create matching content"... That's what I'm trying to duplicate.

  • Nik 1612 posts 7258 karma points MVP 7x c-trib
    Dec 04, 2018 @ 13:17
    Nik
    0

    Hi Chris,

    To hook into the events, you'd need to implement a class that inherits from Application Startup class.

    https://our.umbraco.com/documentation/Reference/Events/Application-Startup

    In here you can access the media and content services and attach to the events which means you can then do what you need.

    Nik

Please Sign in or register to post replies

Write your reply to:

Draft