示例#1
0
        public mediaObjectInfo newMediaObject(object blogid, string username, string password, mediaObject mediaobject)
        {
            Framework.BlogInfo info = Config.CurrentBlog;
            ValidateUser(username, password, info.AllowServiceAccess);

            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.
                Images.EnsureDirectory(Path.Combine(Config.CurrentBlog.ImageDirectory,mediaobject.name.Substring(0, mediaobject.name.LastIndexOf("/") + 1).Replace("/", "\\")));
                FileStream fStream = new FileStream(Path.Combine(Config.CurrentBlog.ImageDirectory,mediaobject.name), FileMode.Create);
                BinaryWriter bw = new BinaryWriter(fStream);
                bw.Write(mediaobject.bits);
            }
            //Any IO exceptions, we throw a new XmlRpcFault Exception
            catch (IOException)
            {
                throw new XmlRpcFaultException(0, "Error saving file.");
            }

            //If all works, we return a mediaobjectinfo struct back holding the URL.
            mediaObjectInfo media;
            media.url = Config.CurrentBlog.ImagePath + mediaobject.name;
            return media;
        }
        public mediaObjectInfo newMediaObject(object blogid, string username, string password, mediaObject mediaobject)
        {
            ValidateUser(username, password, Blog.AllowServiceAccess);
            string imageDirectory = Url.ImageDirectoryPath(Blog);

            try
            {
                // newMediaObject allows files to be overwritten
                // The media object's name can have extra folders appended so we check for this here too.
                FileHelper.EnsureDirectory(Path.Combine(imageDirectory,
                                                        mediaobject.name.Substring(0,
                                                                                   mediaobject.name.LastIndexOf("/",
                                                                                                                StringComparison
                                                                                                                .
                                                                                                                Ordinal) +
                                                                                   1).Replace("/", "\\")));
                string imageFilePhysicalPath = Path.Combine(imageDirectory, mediaobject.name);
                FileHelper.WriteBytesToFile(imageFilePhysicalPath, mediaobject.bits);
            }
            catch (IOException)
            {
                throw new XmlRpcFaultException(0, Resources.XmlRpcFault_ErrorSavingFile);
            }

            mediaObjectInfo media;

            media.url = Url.ImageUrl(Blog, mediaobject.name);
            return(media);
        }
示例#3
0
        public mediaObjectInfo newMediaObject(object blogid, string username, string password, mediaObject mediaobject)
        {
            ValidateUser(username, password, Blog.AllowServiceAccess);
            string imageDirectory = Url.ImageDirectoryPath(Blog);
            try
            {
                // newMediaObject allows files to be overwritten
                // The media object's name can have extra folders appended so we check for this here too.
                FileHelper.EnsureDirectory(Path.Combine(imageDirectory,
                                                        mediaobject.name.Substring(0,
                                                                                   mediaobject.name.LastIndexOf("/",
                                                                                                                StringComparison
                                                                                                                    .
                                                                                                                    Ordinal) +
                                                                                   1).Replace("/", "\\")));
                string imageFilePhysicalPath = Path.Combine(imageDirectory, mediaobject.name);
                FileHelper.WriteBytesToFile(imageFilePhysicalPath, mediaobject.bits);
            }
            catch(IOException)
            {
                throw new XmlRpcFaultException(0, Resources.XmlRpcFault_ErrorSavingFile);
            }

            mediaObjectInfo media;
            media.url = Url.ImageUrl(Blog, mediaobject.name);
            return media;
        }