You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@roller.apache.org by Pieter Steyn <pi...@gmail.com> on 2008/02/01 09:02:48 UTC
XMLRPC Problem
Hi guys,
Could anyone please tell me what I'm doing wrong?
I'm trying to upload an image through xmlrpc via a ruby script (have
tried perl aswel with same results)
Code:
#Ruby code
require 'xmlrpc/client'
server = XMLRPC::Client.new(hostname, /roller/roller-services/xmlrpc, 8080)
stuct = {}
struct["name"] = "newpicture.jpg"
struct["type"] = "image/jpeg"
struct["bits"] = Base64.b64encode(File.read("newpicture.jpg"))
server.call('metaWeblog.newMediaObject', 'blogid', 'username',
'password', struct)
ERROR:
XMLRPC::FaultException: XMLRPC::FaultException
Failed to invoke method newMediaObject in class
org.apache.roller.weblogger.webservices.xmlrpc.MetaWeblogAPIHandler:
java.lang.String cannot be cast to [B
#end code
Any ideas?
(Using Tomcat 6 and Roller 4.0, uploads are enabled and work through
the web interface.)
Thanks,
Pieter Steyn
Re: XMLRPC Problem
Posted by Pieter Steyn <pi...@gmail.com>.
Hi,
Just incase someone has the same problem I had, this is the ruby solution:
image = {
'name' => "img.jpg",
'type' => "image/jpeg",
'bits' => XMLRPC::Base64.new(File.read('/tmp/img.jpg'))
}
Instead of
'bits' => Base64.b64encode(File.read("/tmp/img.jpg"))
Resolved!
Cheers,
Pieter Steyn
> Now if only I could get it working in Ruby, but understand that I
> should probably ask elsewhere regarding that. Thanks again for the
> help, and *if* anyone here knows Ruby and is willing to show me a way
> to do so in Ruby that would be great.
Re: XMLRPC Problem
Posted by Pieter Steyn <pi...@gmail.com>.
Thanks Dave,
I have in the meantime also come across a working Perl example:
# Description: This scripts sends a newMediaObject request
use strict;
use warnings;
use Data::Dumper;
use XMLRPC::Lite +trace => qw(debug);
my $username = "username";
my $password = "password";
my $blogid = "blogid";
my $proxyurl = 'http://spica:8080/roller/roller-services/xmlrpc';
my ($buf,$contents);
open(FILE, "/tmp/img.jpg") or die "$!";
while (read(FILE, $buf, 60*57)) {
$contents .= $buf;
}
my $res = XMLRPC::Lite
->proxy($proxyurl)
->call('metaWeblog.newMediaObject', $blogid, $username, $password,
{ name => "/tmp/img.jpg", type => 'image/jpeg', bits => $contents } )
->result;
if (defined ($res)) {
print "--success--\\n";
print Dumper ($res);
} else {
print "failed: $!";
}
Now if only I could get it working in Ruby, but understand that I
should probably ask elsewhere regarding that. Thanks again for the
help, and *if* anyone here knows Ruby and is willing to show me a way
to do so in Ruby that would be great.
Thanks again and cheers,
Pieter Steyn
> I'm no Ruby guy, but I according to the pickaexe book, Ruby's
> FIle.read() returns a string. What you need is a way to turn a file
> into a byte array. Here's a complete Java example:
> http://tinyurl.com/2nv8ya
>
>
> - Dave
>
RE: roller 4.0 Amazon public AMI
Posted by Boris Milikič <bo...@mf-rs.si>.
Hi!
I have an idea to run a Roller site on S3, but my registrar is unable to set A record and specify alias or CNAME for my amazon domain name. So I could access it only by amazon domain name, for example: http://ec2-67-202-5-162.z-1.compute-1.amazonaws.com/.
So I'm not running it now on S3.
You have opened an account, generated and downloaded private and public key and downloaded their api tools. It takes a day or two at the beginning. But later it takes few minutes to set up an instance und upload to S3.
I think It costs about $60 to run Roller as small instance on the Amazon grid for a month.
On their site is pricing monthly calculator.
http://www.amazon.com/b/ref=sc_fe_l_2?ie=UTF8&node=201590011&no=3435361&me=A36L942TSJ2AJAmonthly
http://calculator.s3.amazonaws.com/calc5.html?
Boris
ps.: mod_jk is not configured in this public image
-----Original Message-----
From: Dave [mailto:snoopdave@gmail.com]
Sent: Tuesday, February 05, 2008 4:11 PM
To: dev@roller.apache.org
Subject: Re: roller 4.0 Amazon public AMI
Very cool. Thanks for sharing. Are you using AWS to run a Roller site?
How hard is it to try this out? And how much does it cost to run Roller on the Amazon grid this way?
- Dave
On Feb 5, 2008 8:41 AM, Boris Milikič <bo...@mf-rs.si> wrote:
>
> I submitted Amazon public AMI for roller 4.0
> AMI ID: ami-e337d28a
> AMI Manifest: roler4.0/image.manifest.xml
>
> http://developer.amazonwebservices.com/connect/entry!default.jspa?cate
> goryID=116&externalID=1186&fromSearchPage=true
>
> Boris
>
Re: roller 4.0 Amazon public AMI
Posted by Dave <sn...@gmail.com>.
Very cool. Thanks for sharing. Are you using AWS to run a Roller site?
How hard is it to try this out? And how much does it cost to run
Roller on the Amazon grid this way?
- Dave
On Feb 5, 2008 8:41 AM, Boris Milikič <bo...@mf-rs.si> wrote:
>
> I submitted Amazon public AMI for roller 4.0
> AMI ID: ami-e337d28a
> AMI Manifest: roler4.0/image.manifest.xml
>
> http://developer.amazonwebservices.com/connect/entry!default.jspa?categoryID=116&externalID=1186&fromSearchPage=true
>
> Boris
>
roller 4.0 Amazon public AMI
Posted by Boris Milikič <bo...@mf-rs.si>.
I submitted Amazon public AMI for roller 4.0
AMI ID: ami-e337d28a
AMI Manifest: roler4.0/image.manifest.xml
http://developer.amazonwebservices.com/connect/entry!default.jspa?categoryID=116&externalID=1186&fromSearchPage=true
Boris
Re: XMLRPC Problem
Posted by Dave <sn...@gmail.com>.
On Feb 3, 2008 7:13 AM, Pieter Steyn <pi...@gmail.com> wrote:
> struct["bits"] = File.read("newpicture.jpg")
>
> But got the same error.
>
> How would I send a byte array using Ruby? Or any other language,
> could you (or anyone else on the list) perhaps provide me with a
> working sample in any language which will do an xmlrpc call to upload
> a mediaobject.
I'm no Ruby guy, but I according to the pickaexe book, Ruby's
FIle.read() returns a string. What you need is a way to turn a file
into a byte array. Here's a complete Java example:
http://tinyurl.com/2nv8ya
- Dave
Re: XMLRPC Problem
Posted by Pieter Steyn <pi...@gmail.com>.
Hi Dave,
Well according to the MetaWebLog API:
>bits is a base64-encoded binary value containing the content of the object.
So yes, struct["bits"] is a string containing a base64 encoding of the
binary file.
I have however tried sending the binary file as is by doing :
struct["bits"] = File.read("newpicture.jpg")
But got the same error.
How would I send a byte array using Ruby? Or any other language,
could you (or anyone else on the list) perhaps provide me with a
working sample in any language which will do an xmlrpc call to upload
a mediaobject.
Thanks alot.
Pieter Steyn
On 2/1/08, Dave <sn...@gmail.com> wrote:
> Looks like a are sending a String and Roller is expecting you to send a "[B"
> which mean a byte.
>
> So, I bet the problem is in the line that starts with struct["bits"]. Are
> you sure you need to use that Base64 call? Maybe you are supposed to set a
> byte array there and let the XMLRPC library do the encoding?
>
>
> - Dave
>
Re: XMLRPC Problem
Posted by Dave <sn...@gmail.com>.
On Feb 1, 2008 3:02 AM, Pieter Steyn <pi...@gmail.com> wrote:
> Could anyone please tell me what I'm doing wrong?I'm trying to upload an
> image through xmlrpc via a ruby script (have
> tried perl aswel with same results)
>
> Code:
> #Ruby code
> require 'xmlrpc/client'
> server = XMLRPC::Client.new(hostname, /roller/roller-services/xmlrpc,
> 8080)
> stuct = {}
> struct["name"] = "newpicture.jpg"
> struct["type"] = "image/jpeg"
> struct["bits"] = Base64.b64encode(File.read("newpicture.jpg"))
> server.call('metaWeblog.newMediaObject', 'blogid', 'username','password',
> struct)
>
> ERROR:
>
> XMLRPC::FaultException: XMLRPC::FaultException
>
> Failed to invoke method newMediaObject in class
> org.apache.roller.weblogger.webservices.xmlrpc.MetaWeblogAPIHandler:
> java.lang.String cannot be cast to [B
>
Looks like a are sending a String and Roller is expecting you to send a "[B"
which mean a byte.
So, I bet the problem is in the line that starts with struct["bits"]. Are
you sure you need to use that Base64 call? Maybe you are supposed to set a
byte array there and let the XMLRPC library do the encoding?
- Dave