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
  • 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 )? Commented Jul 15, 2012 at 2:43

4 Answers 4

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">
Sign up to request clarification or add additional context in comments.

Comments

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)"

Comments

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.

1 Comment

I got them same problem with several images, that all fit the constraints. Problem is in the encoding of the image
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.

1 Comment

Actually the error happens both with and without encoding the image.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.