Copied to clipboard

Flag this post as spam?

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


  • Ken Cowley 10 posts 29 karma points
    Aug 02, 2013 @ 01:05
    Ken Cowley
    0

    Uploading media using media service

    I have a WCF servuce which consumes the media service to allow me to view and upload media items. 
    public int UploadMediaFile(MediaFileDataContract mediaFile, string campaignUrl)
            {          
                using (var proxy = new UmbracoMediaService.mediaServiceSoapClient("mediaServiceSoap", string.Format("{0}umbraco/webservices/api/MediaService.asmx", campaignUrl)))
                {
                    string extension = System.IO.Path.GetExtension(mediaFile.TemplateName);
                    string fileName = mediaFile.TemplateName.Substring(0, mediaFile.TemplateName.Length - extension.Length); ;
    
                    if (proxy != null && IsUserAuthenticated(campaignUrl, username, password))
                    {
                        UmbracoMediaService.mediaCarrier media =
                            new UmbracoMediaService.mediaCarrier
                            {
                                ParentId = ParagoRootId,
                                TypeAlias = "File",
                                TypeId = 1033,
                                Text = fileName,
                                MediaProperties = new UmbracoMediaService.ArrayOfMediaProperty()
                            };
    
                        media.MediaProperties.Add(new UmbracoMediaService.mediaProperty { Key = "umbracoExtension", PropertyValue = extension.Replace(".", "") });
                        media.MediaProperties.Add(new UmbracoMediaService.mediaProperty { Key = "umbracoBytes", PropertyValue = "" });
                        media.MediaProperties.Add(new UmbracoMediaService.mediaProperty { Key = "umbracoFile", PropertyValue = mediaFile.TemplateName });
    
                        media.Id = proxy.create(media, username, password);
    
                        proxy.writeContents(media.Id, mediaFile.TemplateName, mediaFile.mediaData, username, password);                    
    
                        proxy.update(media, username, password);
    
                        return media.Id;
                    }
                }
                return 0;
            }
    I am having some difficulty uploading a new media item. My code is as follows:public int It runs without error and I can see that the media item is created in Umbraco and that the file is copied to the media folder. However the link to the media item file is not being set and as such the item dese not belive that a file is loaded. Can anybody spoit what I have done wrong.ThanksKen
Please Sign in or register to post replies

Write your reply to:

Draft