Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: raw image data?

by kwaping (Priest)
on Apr 21, 2009 at 17:04 UTC ( [id://759056]=note: print w/replies, xml ) Need Help??


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

Did you binmode the filehandle?

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

Replies are listed 'Best First'.
Re^4: raw image data?
by 23skiddoo (Beadle) on Apr 21, 2009 at 17:53 UTC
    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

      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
      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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-03-29 11:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found