예제 #1
0
        public mediaObjectInfo newMediaObject(object blogid, string username, string password, mediaObject mediaobject)
        {
            CreateServices();

            ValidateUser(username, password);

            try
            {
                //We don't validate the file because newMediaObject allows file to be overwritten
                //But we do check the directory and create if necessary
                //The media object's name can have extra folders appended so we check for this here too.
                var path = imageFileService.GetFullPath(mediaobject.name.Replace("/", "\\"));

                if (!Directory.Exists(Path.GetDirectoryName(path)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(path));
                }

                using (var fileStream = new FileStream(path, FileMode.Create))
                    using (var binaryWriter = new BinaryWriter(fileStream))
                    {
                        binaryWriter.Write(mediaobject.bits);
                    }
            }
            //Any IO exceptions, we throw a new XmlRpcFault Exception
            catch (IOException exception)
            {
                throw new XmlRpcFaultException(0, exception.Message);
            }

            ////If all works, we return a mediaobjectinfo struct back holding the URL.
            mediaObjectInfo media;

            media.url = baseControllerService.SiteUrl + imageFileService.GetRelativeUrl(mediaobject.name);
            return(media);
        }
예제 #2
0
        public mediaObjectInfo newMediaObject(object blogid, string username, string password, mediaObject mediaobject)
        {
            CreateServices();

            ValidateUser(username, password);

            try
            {
                //We don't validate the file because newMediaObject allows file to be overwritten
                //But we do check the directory and create if necessary
                //The media object's name can have extra folders appended so we check for this here too.
                var path = imageFileService.GetFullPath(mediaobject.name.Replace("/", "\\"));

                if (!Directory.Exists(Path.GetDirectoryName(path)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(path));
                }

                using (var fileStream = new FileStream(path, FileMode.Create))
                using (var binaryWriter = new BinaryWriter(fileStream))
                {
                    binaryWriter.Write(mediaobject.bits);
                }
            }
            //Any IO exceptions, we throw a new XmlRpcFault Exception
            catch (IOException exception)
            {
                throw new XmlRpcFaultException(0, exception.Message);
            }

            ////If all works, we return a mediaobjectinfo struct back holding the URL.
            mediaObjectInfo media;
            media.url = baseControllerService.SiteUrl + imageFileService.GetRelativeUrl(mediaobject.name);
            return media;
        }