Media api returning error "Segments do not add up to provided total file size"

restapi
video
media-upload

#1

Hello,
Video i am trying to upload is 152Kb in size and around 16 seconds of length.
This is the function i have written.

function uploadVideo() {
    Token.post('media/upload', { command: "INIT", media_type: "video/mp4", total_bytes: 152000 }, function (error, media, response) {
        if (error) {
            console.log(error);
        }
        else {
            var mediaObject = media;
            Token.post('media/upload', { command: "APPEND", media_id: mediaObject.media_id_string, segment_index: 0, media: "/Users/mukeshagicha/Documents/workspace/buzz-twitter-crawl/sample-video.mp4" }, function (error, media, response) {
                if (error) {
                    console.log(error);
                } else {
                    console.log(response.statusCode);
                    Token.post('media/upload', { command: "FINALIZE", media_id: mediaObject.media_id_string}, function (error, media, response) {
                        if (error) {
                            //getting error here
                            console.log(error);
                        } else {
                            console.log('successfully created media');
                            //TO DO: api to post status with media 
                        }
                    });
                }
            });
        }
    });
}

Errors Uploading Chunked Images to Twitter via OAuth.io
#2

@mukesh_agicha Please could you provide an example mediaId from INIT response?


#3

@tushargj
following is the INIT response

media Object :{ media_id: 776317709789175800,
media_id_string: ‘776317709789175808’,
expires_after_secs: 86399 }

Response StatusCode : 202


#4

@tushargj
Resopnse StatusCode from APPEND state is 204 .


#5

@mukesh_agicha That error indicates that APPEND command(s) is sending more or less data in total than 152000 bytes. It will be easy to debug if you could post http request/response trace logs :slight_smile:


#6

@tushar_io
The following is the request header for append call
{
Accept: ‘/’,
‘User-Agent’: ‘twit-client’,
‘Content-type’: ‘application/x-www-form-urlencoded’,
‘accept-encoding’: ‘gzip’,
‘content-length’: 152,
Authorization: ‘OAuth oauth_consumer_key=“1CCLKpVh3XZcdcvJ8jViCLbed”,oauth_nonce=“660a32d429af47eda33afe343f5abdd8”,oauth_signature_method=“HMAC-SHA1”,oauth_timestamp=“1474266416”,oauth_token=“2494679864-MlC1aOX8WTGvM0nUqNPmz1D9QCsuEK9hKzxzmn1”,oauth_version=“1.0”,oauth_signature=“tgnx%2B4UXpealypZueLsrUQCoOU4%3D”’
}
The response statusCode is 204 and status message is “No Content”,
the i am confused that since in request header it can read content-length to be :152 so how am i getting No Content as Status Message.


#7

@mukesh_agicha APPEND command allows you to upload media file progressively in small chunks. You can send 1 or more chunks using APPEND which is why it returns 204 in your case. You will get the error when you try to call FINALIZE because you are just providing 152 bytes instead of 152000 bytes specified in INIT.


#8

@tushar_io the size of file is 152KB and Append call is providing only 152 bytes how do i correct it. can we specify what chunk size to be send while uploading video in chunks(APPEND METHOD) or is there any default size set with append call.
P.S : Sorry for troubling you a bit :sweat_smile: i am kind of a new to using twitter api and also a fresher in IT so having bit of trouble and asking some stupid questions thanks for help.


#9

@mukesh_agicha No problem. Everyone is a beginner at some point in time. Due to time constraints, I won’t be able to help you debug this further. I would recommend you to go through our API docs and any relevant examples if possible.


#10

@tushar_io Just a follow up to this question.

I can upload using this method without issue, but seemingly randomly I will have an upload fail with this error. I’m trying to track the individual APPEND requests that are failing or not delivering the correctly sized chunk, but all of my APPEND requests return a status code of 204.

What should I look for in the response to debug this?

cc andypiper


#11

Hi mukesh,
I am also getting the same issue while calling FINALIZE . Can you help me further how to resolve it.

Thanks,
Krishna


#12

This is a issue we are also encountering intermittently. The code is same but sometime it works and sometime it does not. Any insight of what to check in a video to make sure it is not the content size which is the issue. We are trying with 117MB video of 7 mins.