This patch extends Antville's metaWeblog.newMediaObject() xml-rpc function to recognize images and save them as image objects instead of file objects. It also 'enriches' the returned struct. See also http://blogs.23.nu/c0re/stories/234/comments/284 --md@hudora.de, 2003 --- antville/metaWeblog/metaWeblogAPI.js Thu Jul 24 20:20:58 2003 +++ /usr/local/helma/apps/antville/metaWeblog/metaWeblogAPI.js Fri Jul 25 06:30:31 2003 @@ -231,8 +231,18 @@ * @param fileObject Object, containing the following properties * .bits base64, the base64-encoded contents of the file * .name String containing the filename - * .type String - * @return String containing the URL of the uploaded file + * .type String representing a MIME-type + * .description String (optional) description of the object + * @return Object, containing the following properties + * .url String containing the URL of the uploaded file + * .alias Sting containing the alias of the uploaded file + * .message String human readable message indicating success + * .macro String a macro which can be embedded into storys to insert this object + * .thumbmacro String (optional) a macro to display a thumbnail + * .staticUrl String (optional) url of the Image + * .popupUrl String (optional) javascript code to open a popup with the image + * .width Int (optional) the width of the image + * .heigth Int (optional) the heigth of the image */ function newMediaObject(blogid, username, password, fileObject) { var usr = root.blogger.getUser(username,password); @@ -242,15 +252,43 @@ var str = new java.lang.String(fileObject.bits); var bytes = Packages.helma.util.Base64.decode(str.toCharArray()); var param = new Object(); + var ret = new Object(); + + if (fileObject.type.substring(0, 6) == "image/") { + param.rawimage = new Packages.helma.util.MimePart(fileObject.name, bytes, fileObject.type); + + var result = blog.images.evalImg(param, usr); + if (result.error) + throwError ("Error occured while creating new Media Object: "+result.message); + else { + var alias = param.alias; + var file = blog.images.get(alias); + file.alttext = fileObject.description; + ret.staticUrl = file.getStaticUrl(); + ret.popupUrl = file.popupUrl(); + ret.width = file.width; + ret.heigth = file.heigth; + ret.macro = "<% image name=\""+alias+"\" %>"; + if (file.thumbnail) { + ret.thumbmacro = "<% image name=\""+alias+"\" as=\"thumbnail\"%>"; + } + } + } else { param.rawfile = new Packages.helma.util.MimePart(fileObject.name, bytes, fileObject.type); - var result = blog.files.evalFile(param, urs); + var result = blog.files.evalFile(param, usr); if (result.error) - throwError ("Error occured while creating new Media Object"); + throwError ("Error occured while creating new Media Object: "+result.message); else { - var alias = buildAliasFromFile(param.rawfile); + var alias = param.alias; var file = blog.files.get(alias); - return (getProperty("fileUrl")+blog.alias+"/"+file.name); + file.description = fileObject.description; + ret.macro = "<% file name=\""+alias+"\" %>"; + } } + ret.url = file.url; + ret.alias = alias; + ret.message = result.message; + return (ret); }