How do i post a base 64 image to statuses/update_with_media


#1

Hi Guys,

I want to post an image to twitter api.
If i use an binary image everything is working fine but i want to use base64 to post the image to the api.

I’ve tryed everything i know but i keep getting the
data: ‘{“errors”:[{“code”:189,“message”:“Error creating status”}]}’,
error.

These are my headers:

-----------------------------d67b3e07c45e Content-Disposition: form-data; name="status"

asdasdasd
-----------------------------d67b3e07c45e
Content-Disposition: form-data; name=“include_entities”

1
-----------------------------d67b3e07c45e
Content-Disposition: file; name=“media[]”; filename=“test.png”

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIgAAAB+CAIAAABwE84BAAAYKGlDQ1BJQ0MgUHJvZmlsZQAAWAmtWXk81N/Xv59ZzRjbjH3f933f933JEqKQMfa9sYuitKGFZC+RlIhK2VJZKilEiURlSYiKpBB5PqN8v7/n9TzPf8 (… keeing it smal for the post)

-----------------------------d67b3e07c45e–

If i dont add an image everything is working fine.

I’m using node js.

Does enybody know what i’m doing wrong?


#2

Currently base64 encoded images aren’t accepted by the API. We’ll work on adding support for this but you should continue to send the raw binary data instead.


#3

Kurrik thanx for your reply!

I already build it that way. Was not an big isseu.

Can i ask you to take a look at my application? Like to know what u think about it.
Why i ask is because i’m depanding on Twitter right know and i want to know if Twitter aproves my application. We want to open our application for other users. If we do i know about 50 to 70% of the biggest accounts (100K +) wil be in this application. (The are asking about the appication daily ( in whatsapp ))
I don’t want to mess things up on Twitter side and all the accounts that wil be in our application.

OOO, And site Stream would be awsume!

Thnx!


#4

Does this still apply? No base64 is accepted? Or was this fixed in the meantime?

Thanks.


#5

Reading the documentation, it seems to accept base64 string, but I can’t use.
Is this fault of my code? or base64 not allowed yet?


#6

I dont know realy but binary is easy to. What language are u coding in?


#7

Thanks!

I’m using JavaScript (in Chrome Extension OAuth), and also using HTML5 Canvas API.
Canvas gives base64 string more easily than image binary.


#8

Take a look at:
http://vabate.com/convert-a-base64-encoded-string-to-binary-with-javascript/


#9

Hi… I am also trying to upload binary image… Could you please share your code?


#10

You can upload your media base64 encoded. Take a look at https://dev.twitter.com/docs/uploading-media


#11

We allow uploading your media base64 encoded or binary. Check out https://dev.twitter.com/docs/uploading-media


#12

Thanks a lot!


#13

pass a parameter likes below may works:
array(‘media[]’ => file_get_contents($image_url),‘status’ =>$status_sent)


#14

@jaakkosf …is it possible to send binary image data to media parameter. or should we only specify filepath.


#15

You should not specify a filename/path in the media parameter, as that is a local thing, not visible to the API. You need to include the base64 data.


#16

@andypiper I did specify base64 but no luck. Its complaining about authentication 401.


#17

@andypiper…I tried to change callback url (eg:http://applicationname.com/) and generate new access and consumer key…but no luck. Can you please check details below of my header.

	<Header>POST / HTTP/1.1accept: application/json
authorization: OAuth oauth_signature="PPCcO%2BHTDGhl42v********%3D", oauth_version="1.0", oauth_nonce="ee589a7e-b221-4e****", oauth_consumer_key="oJFOmo4i5NkxuV******", oauth_signature_method="HMAC-SHA1", oauth_token="2894909697-lEcJkDj2abplxgZh3vLo9Zm******", oauth_timestamp="1418819912"

accept-encoding: gzip

content-type: text/plain

user-agent: Java/1.7.0_55

host: localhost:8336
connection: keep-alive
content-length: 0

  

      </Header>
        <Protocol>HTTP</Protocol>
        <Port>8336</Port>
    <Headers>
    	<Accept>application/json</Accept>
	

    <Accept-Encoding>gzip</Accept-Encoding>
    	<Content-Type>text/plain</Content-Type>
    	<Content-Length>0</Content-Length>
    	<Connection>keep-alive</Connection>
    </Headers>