Subject: | photo uploads |
Date: | Thu, 16 Aug 2007 22:23:39 +0200 |
To: | bug-www-facebook-api [...] rt.cpan.org |
From: | "Kalle Bingel" <kalle.bingel [...] gmail.com> |
Hi,
I'm experiencing problems uploading photos, I will always get an "324
Missing or invalid image file." from facebook...
After reading and doing some snooping, I found out that the problem
might be in the way www-facebook-api is encoding the parameters. It
(seems like it) currently sends all parameters using the "simple"
format (application/x-www-form-urlencoded), BUT when doing photo
uploads, facebook requires the parameters to be sent in MIME multipart
format (this according to the following page:
http://wiki.developers.facebook.com/index.php/Photos.upload). LWP
supports this format with a quite easy implementation, so it should
not be a big deal to change...
I have gotten it to work by modifying API.pm and replacing the
_post_request with the following:
sub _post_request {
my ( $self, $params, $secret, $sig, $post_params ) = @_;
my $data = $params->{'data'}; # save data parameter
delete $params->{'data'};
$self->_format_params($params);
$sig = $self->generate_sig( params => $params, secret => $secret );
$post_params = [ map { $_ => $params->{$_} } sort keys %{$params} ];
push @{$post_params}, q{sig}, $sig;
if( defined $data) { # add data parameter to request, also
specifying content-type
push( @{$post_params}, 'data', [ undef, 'filename',
'Content-Type' => 'image/jpeg', 'Content' => $data ]);
}
# Setting Content_type to 'form-data' makes LWP encode it as multipart MIME
return $self->ua->post( $self->server_uri, 'Content_type' =>
'form-data', 'Content' => $post_params)->content;
}
This works for me, and I've uploaded several photos to facebook this
way... HOWEVER... after looking through and trying to understand the
facebook API better as well as this perl module, I suddenly realized
that my code alteration should not really work. It does not include
the photo data in the signature (I remove it from the $params hash,
then it gets encoded and the signature is generated, and then I add it
to the parameter list again)... so my code seems as it should generate
a signature error, but it doesn't... BUT it sure does when I tried to
correct my "bug"... so I don't understand anything... and by the way,
my take on the situation is really cludgy anyway, so I hope you can
take this input and perhaps do something better with it in a future
release?
OR, maybe you have already another solution ready which I haven't found yet?
Thanx!
--Kalle
PS Also, I think you should do something about the 64-bit integer
problem as I suspect you're aware of (aid and other parameters are
64-bit when returned from facebook, and JSON parses it and perl stores
it as a float and looses precision in the process)... the workaround
with "use JSON::Any qw(DWIW XS);" I found somewhere currently works
for me, but anyway...