3

I want to upload an image from my hard drive, using an html form:

Image file: <input name="imageupload" id="imageupload" type="file" />

Then I upload it to twitter with:

image=self.request.get('imageupload')
image2=base64.b64encode(image)
twitapi.Update_profile_image(image=image2)

given twitapi.Update_profile_image:

def Update_profile_image(self,image):
    if not self._oauth_consumer:
        raise TwitterError("The twitter.Api instance must be authenticated.")

    url = '%s/account/update_profile_image.json' % (self.base_url)
    data = {'image':image}

    json = self._FetchUrl(url, post_data=data)
    data = self._ParseAndCheckTwitter(json)
    return data

Given _FetchUrl from twitter-api

I always get

TwitterError: There was a problem with your picture. Probably too big.

Any ideas whee it comes from? Thanks!

  • 1
    Have you verified the success of each step along the way? Is the image uploading correctly? Is self.request.get('imageupload') getting the file? Can you display the image elsewhere after encoding (try jsfiddle.net/hpP45 )? – Jay Neely Jul 15 '12 at 2:43
2

Twitter RESTful API Document is not correct.
Do NOT encode image binary to base64! Remove base64 encode section from your source.

If you encode image binary to base64 string, twitter api says

"... was a problem with your picture probably too big. (...) (code 131)"

2

To submit ah image correctly via a form, you have to include

enctype="multipart/form-data" 

eg

<form  enctype="multipart/form-data" action='/' method="POST">
1

Perhaps the image you are receiving via the form upload is already base64 encoded ?

You are then applying a double encoding which could confuse the validation on the twitter server side because it would be unable to find a typical image header in your uploaded file.

  • Actually the error happens both with and without encoding the image. – user375348 Jul 13 '12 at 21:07
1

As per the documentation, your image:

Must be a valid GIF, JPG, or PNG image of less than 700 kilobytes in size.

So make sure your image fits within these constraints. Maybe you need to scale down your image, or convert it to a different format.

If that doesn't work, try uploading another very tiny image that meets the constraints above. At least you can then verify whether or not the problem lays with the particular image you are using.

  • I got them same problem with several images, that all fit the constraints. Problem is in the encoding of the image – user375348 Jul 13 '12 at 5:49

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.