Copied to clipboard

Flag this post as spam?

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

  • Michael Chart 15 posts 35 karma points
    Jun 20, 2013 @ 18:42
    Michael Chart

    Umbraco 6 - uploading media files programatically

    I am trying to create a media item programatically, including uploading an image in Umbraco 6. I am using the new MediaService and calling mediaService.CreateMedia(mediaName, parentFolder, "Image"). That is all working fine, but what I don't know how to do is how to upload the file.

    I have seen this post:

    Which seems to get the media root directory and create the folders and files manually. This doesn't seem to work in Umbraco 6, as HttpContext.GetGlobalResourceObject("AppSettings", "MediaFilePath") is null. 

    How should I upload media files in Umbraco 6?


  • Michael Chart 15 posts 35 karma points
    Jun 21, 2013 @ 13:51
    Michael Chart

    I suppose I was expecting there to be some methods exposed in the API for doing this sort of thing. For now, I have just used the code from the above post ( and just replaced HttpContext.GetGlobalResourceObject("AppSettings", "MediaFilePath") with a static reference to the media folder.


  • Mark Slade 42 posts 93 karma points
    Apr 07, 2014 @ 10:34
    Mark Slade

    Hi Michael,

    Did you ever get an answer to this? I'm facing the same issue.


  • Michael Chart 15 posts 35 karma points
    Apr 08, 2014 @ 10:03
    Michael Chart

    Hi Mark,

    No - I ended up just doing what I described above. Not really sure what the official way to do such a thing is - sorry I can't be much more help.


  • Gerty Engrie 122 posts 472 karma points c-trib
    Jun 20, 2014 @ 11:25
    Gerty Engrie

    Hello :-) 

    have you tried this? Mediaurl is a path here, so something like /myimages/test.jpg

    var mediaService = ApplicationContext.Current.Services.MediaService;
    var media = mediaService.CreateMedia(property + "-" + id, 2111, "Image");
    media.SetValue("umbracoFile", mediaurl.Substring(mediaurl.LastIndexOf("/") + 1), new System.IO.FileStream(System.Web.Hosting.HostingEnvironment.MapPath(mediaurl), System.IO.FileMode.Open));


    return media.Id;


Please Sign in or register to post replies

Write your reply to: