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;
}