Errors Uploading Chunked Images to Twitter via OAuth.io

media-upload

#1

NB: a minimum-viable-example exists here, with text copied from below.

We are unable to reliably upload images to Twitter.

Twitter has a REST API endpoint for uploading chunked images. We are using OAuth.io to interact with Twitter. We are uploading the image as a base64 string.

If we upload an image in a single chunk, then the image uploads to Twitter without any problem. However, if we split the same image into multiple chunks, then Twitter may:

  1. refuse to upload the image, informing us that the Segments do not add up to provided total file size once the FINALIZE command is called;
  2. accept the the image, but display a corrupted image in the tweet.

The error behavior varies based on the individual file used and the chunk size of our upload. However, we have not been able to determine any viable rules to guarantee success, and certain files seem to be more error prone than others.

Without the ability to introspect what OAuth.io is POSTing or what Twitter is receiving, we are unable to determine where the problem may be occurring.

The code to demonstrate this behavior is quite long (~200 lines of JS, not including the base64 images or HTML). I’ve published a full working example here for people to interact with. The code from the example available on Github.

Thanks in advance!


#2

Thanks for the detailed report and examples. I’ve moved this thread over to our Media APIs category, and will see if the team has time to take a look and help here. Are you successfully able to use our large media upload example to post images?


#3

Hi Andy,
Thanks for the quick reply.

If I use the example as is (uploading in binary in a single chunk), then the upload works without issue.

However, when I modify the large media upload example to send images in base64, and when I split the chunk of icon.jpg as described in the documentation above, I am able to replicate the error described.

You can see my changes in my fork of the example project. Here is a link to the relevant diff.

The error that is printed out is:

INIT
Media ID: 773535012268507136
APPEND
2666 of 5332 characters uploaded
APPEND
5332 of 5332 characters uploaded
Upload chunks complete.
FINALIZE
{'request': '/1.1/media/upload.json', 'error': 'Segments do not add up to provided total file size.'}
{'errors': [{'message': 'Invalid media id 773535012268507136', 'code': 324}]}

As with the previous example, changing the chunk size leads to different results.


#4

Hi @andypiper,
Is there anything else I can do to help with the problem?

Thanks,
Andrew


#5

Hi there - sorry for not having followed back up on this. We’ve got an open ticket internally to try to have a look at this, but with various things in motion we can’t always get to every issue as quickly as we’d like. It does look like someone else is encountering a similar issue, so I’ll see if there’s any common cause here.

summary - looking into it, no specific outlook for a full resolution for you, but I don’t think there’s too much else you can add at the moment.


#6

Hi,
No problem. Thanks for the quick response!

That all sounds great. If there’s anything I can do, please let me know.

Andrew


#7

Sorry meant to link to the related thread, in case you spot anything in there that seems common or inspires you!


#8

@jambonrose Are you applying base64 encoding before or after INIT? You must pass the actual total size of original media (without base64) in INIT command.


#9

@tushargj:


#10

Thanks @jambonrose. Please could you also post http request/response logs?