Monday, November 08, 2010 at 12:05 AM.

system.verbs.builtins.radio.weblog.metaWeblogApi.rpcHandlers.newMediaObject

on newMediaObject (blogid, username, password, struct) {
	<<Changes
		<<9/9/04; 9:07:07 PM by SK
			<<Added code to determine media type.  If it's an image, place the new media object in Radio's default image directory.  Everything else, place in the gems directory.
		<<1/11/03; 5:31:47 PM by JES
			<<Added code to get the MacOS type/creator.
		<<1/10/03; 8:22:39 AM by DW
			<<Created.
			<<http://www.xmlrpc.com/discuss/msgReader$2393
	radio.weblog.bloggerApi.checkUser (client, true, username, password);
	radio.weblog.bloggerApi.checkBlogid (blogid);
	
	local (name = struct.name);
	bundle { //add extension to name
		if not (name contains ".") {
			local (adr, type = string.lower (struct.type));
			for adr in @user.webserver.prefs.ext2MIME {
				if type == string.lower (adr^) {
					name = name + "." + nameof (adr^);
					break}}}};
	local (type = '    ', creator = '    ');
	if system.environment.isMac { //get mac type/creator
		local (adrtype, mimetype = string.lower (struct.type));
		for adrtype in @user.webserver.prefs.type2Mime {
			if string.lower (adrtype^) == mimetype {
				type = nameOf (adrtype^);
				if string.lower (adrtype^) beginsWith "image/" {
					creator = user.html.prefs.imgFileCreator}}}};
	
	//determine filesystem destination--parse text for struct.name, convert slashes to correct file.getPathChar and assign to a variable "name"
	if system.environment.isMac {
		name = string.replaceAll (name, "/", ":")}
	else {
		name = string.replaceAll (name, "/", "\\")};
	
	
	
	local (f); //f is the upstreamed file location for Radio weblogs--images for images, gems for everything else
	if struct.type contains "image" {
		f = user.radio.prefs.wwwFolder + radio.data.folderNames.wwwImagesFolderName + file.getPathChar () + name;
		if file.sureFilePath (f) {
			file.writewholefile (f, struct.bits, type, creator)}
		else {
			file.newFolder (f)}}
		<<file.writewholefile (f, struct.bits, type, creator)
	else {
		f = user.radio.prefs.wwwFolder + radio.data.folderNames.wwwGemsSubFolderName + file.getPathChar () + name;
		file.writewholefile (f, struct.bits, type, creator)};
	local (returnedstruct);
	new (tabletype, @returnedstruct);
	returnedstruct.url = radio.upstream.getFileUrl (f);
	return (returnedstruct)}
<<bundle //test code
	<<local (struct, client = "127.0.0.1")
	<<bundle //set up struct
		<<new (tabletype, @struct)
		<<struct.name = "steve-suit.jpg"
		<<struct.type = user.webserver.prefs.ext2MIME.jpeg
		<<struct.bits = binary (file.readwholefile ("C:\\Documents and Settings\\skirks\\My Pictures\\stevesmile.jpg"))
	<<newMediaObject ("home", user.radio.prefs.security.remoteUsername, user.radio.prefs.security.remotePassword, struct)



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.