Copied to clipboard

Flag this post as spam?

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


  • lj 81 posts 425 karma points
    Sep 12, 2013 @ 16:53
    lj
    0

    trying to upoad image from disk to umbraco (v6.1.5) using mediaService.CreateMedia

    Hi

    trying to upoad image from disk to umbraco (v6.1.5) using  mediaService.CreateMedia. Using mediaService.CreateMedia I can create the media object in umbraco which can be viewed from admin.

    Problem I am having is getting the actual image uploaded to umbraco.

    Tried    

    var media = mediaService.CreateMedia("xxxx", 2553, "Image");

    string fileLocation = "C:\\location\\imagename.jpg";
    byte[] newImage = null;
    newImage = File.ReadAllBytes(fileLocation);

    media.SetValue("umbracoFile", newImage );
    mediaService.Save(media);

    but throws error

    Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The best overloaded meth
    d match for 'Umbraco.Core.Models.ContentBase.SetPropertyValue(string, string)'
    as some invalid arguments
       at CallSite.Target(Closure , CallSite , Object , String , Object )

     

    Has anyone used this api for this?

     

    Update:- Got a solution from http://our.umbraco.org/forum/developers/api-questions/38533-How-do-you-SaveUpload-a-file-to-Media-using-the-new-MediaService-API?p=0#comment139687 which works from a web app but still getting error in console app if get it working will update post with fix.

    Update:- Got console app working following from http://www.wiliam.com.au/wiliam-blog/web-design-sydney-umbraco-6-and-the-servicecontext.

  • lj 81 posts 425 karma points
    Sep 13, 2013 @ 10:07
    lj
    100
  • Arjan 9 posts 62 karma points
    Oct 02, 2013 @ 23:25
    Arjan
    0

    A MemoryStream and File.ReadAllBytes was my key to success. Tried ALL other .NETfx options :)

    var image = MediaService.CreateMedia("MyIMAGE", parent, "Image"); 
    byte[] buffer = System.IO.File.ReadAllBytes(file);
    MemoryStream strm = new MemoryStream(buffer);
    image.SetValue("umbracoFile"
    "MyImage.PNG", strm);
    MediaService.Save(image);
Please Sign in or register to post replies

Write your reply to:

Draft