Copied to clipboard

Flag this post as spam?

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


  • kukuwka 75 posts 96 karma points
    Mar 30, 2011 @ 13:57
    kukuwka
    0

    Create media using service

    Hi,

    I want to create new media using service that run every 5 hours.

    My code is:

    var media = Media.MakeNew(name, new MediaType(typeId), new User
    (0), parentId);
    media.Save();
    return media.Id;

    But I receive the next error:

       at Cultiv.MediaLibraryCache.MediaCache.Cache(String cacheName)
       at Cultiv.MediaLibraryCache.MediaCache.RemoveFromCache(Int32 id)
       at Cultiv.MediaLibraryCache.MediaRemoveCacheHandler.RemoveFromCache(Int32 id)
       at Cultiv.MediaLibraryCache.MediaRemoveCacheHandler.SaveRemoveCacheItem(Media sender, SaveEventArgs e)
       at umbraco.cms.businesslogic.media.Media.FireAfterSave(SaveEventArgs e) in d:\TeamCity\buildAgent\work\7380c184e9fcd3ea\umbraco\cms\businesslogic\media\Media.cs:line 214
       at umbraco.cms.businesslogic.media.Media.Save() in d:\TeamCity\buildAgent\work\7380c184e9fcd3ea\umbraco\cms\businesslogic\media\Media.cs:line 41
      

    How can I avoid it?

    Thanks,

     kukuwka

  • Chris Randle 65 posts 176 karma points c-trib
    Jul 13, 2011 @ 19:07
    Chris Randle
    0

    I am a bit of a newcomer to this Umbraco stuff - but I suspect that you are trying to using the Save method of the Media object without having a valid database connection underneath.   You are using Team City and it may be that it doesn't have sufficient privileges to host the application and connect to the database.  Basically - enough rights to save the Media object.

    Or alternatively, perhaps you can only call it from a valid HttpContext session.  Since Umbraco isn't running unless you have a current session open, this would explain this error message a little.

    Media.Save() should only be called directly from within a page. You need to look at another method of inserting Media.  I suspect using a valid webservice might do the trick.

     

Please Sign in or register to post replies

Write your reply to:

Draft