Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: raw image data?

by 23skiddoo (Beadle)
on Apr 21, 2009 at 17:53 UTC ( [id://759073]=note: print w/replies, xml ) Need Help??


in reply to Re^3: raw image data?
in thread raw image data?

A flash of hope! But, alas, that did not work. I tried both
open my $fh, "<", $img or die "Can't open $img: $!"; my $raw = <$fh>;
and
open my $fh, "<:raw", $img or die "Can't open $img: $!"; my $raw = <$fh>;
I know my use of Net::Twitter works to post text, it's just this picture updating that is failing. I suppose it could be a problem with the module itself. Maybe I should try it with some LWP or REST mojo...?
fnord

Replies are listed 'Best First'.
Re^5: raw image data?
by ikegami (Patriarch) on Apr 21, 2009 at 19:42 UTC

    fyi, :raw turns off buffering too, that's why I used :raw:perlio.

    You also only read up 'til the first \x0A. Not very useful.

    I tried a similar route before coming to the monastery

    Similar, but worlds apart. Did you actually try the code we provided, or did you just dismiss them as similar enough.

      I really tried them both, using copy-and-paste into vim for your solution. :( I will post my full code shortly.
      fnord
Re^5: raw image data?
by zwon (Abbot) on Apr 21, 2009 at 19:07 UTC
Re^5: raw image data?
by kwaping (Priest) on Apr 21, 2009 at 19:11 UTC
    Please post your code, and a dump of the results from get_error() after a failed image upload attempt.
    Thanks!

    ---
    It's all fine and dandy until someone has to look at the code.
      Here is my test code. "foo.png" is a 323KB file in the cwd.
      #!/usr/bin/perl -w use strict; use Net::Twitter; $\ = "\n"; my $img = "foo.png"; # Translate image to a raw format my $raw = do { open ( my $fh, '<:raw:perlio', $img ) or die "Can't open image file $img: $!"; local $/; <$fh>; }; # Create a connection to twitter my $twit = Net::Twitter->new( { username => "fake_uid", password => "fake_pwd", } ); # Post the image file $twit->update_profile_image( $raw ); # Grab the error hash ref and roll through it my $err = $twit->get_error; foreach my $key ( sort keys %{ $err } ) { print STDERR "$key => $err->{ $key }"; }
      And the dump of the $err hash ref:
      error => There was a problem with your picture. Probably too big. request => /account/update_profile_image.json
      The "probably too big" is not a very good error message, is it? :) I also tried it with a 5px x 5px file and it spat out the same error. As I said earlier, the connection to twitter is working, because I can successfully post using the update() method.
        Thanks for posting your code and the errors. I don't see anything obviously wrong with your code. These are the only suggestions I can think of:
        1. Try printing $raw to a local file and see if you can successfully view it with an image program.
        2. Google around to see if Twitter's API might be broken for that function.
        Good luck!

        ---
        It's all fine and dandy until someone has to look at the code.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://759073]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-23 11:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found