New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media upload not working as it seems it should in test case. #646

Closed
barkermn01 opened this Issue Apr 18, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@barkermn01

barkermn01 commented Apr 18, 2018

So I have double checked this against the test case and for some reason, it does not work for me.

// get media s3 path
$s3Path = $imagePath = "https://s3-eu-west-1.amazonaws.com/beacon.media/".($media->path);
$fileExt = explode(".", $media->path);
$fileExt = end($fileExt);
// download the file from s3 to /tmp/		
$tmpPath = sys_get_temp_dir()."/".sha1(time())."_".sha1(microtime()).".{$fileExt}";
$fh = fopen($tmpPath, "w");
fwrite($fh, $s3->download($media->path));
fclose($fh);

// call the upload (taken from /tests/TwitterOAuthTest.php:218
$response = $this->getConnection()->upload("media/upload", array("media" => $tmpPath, "media_type" => "video/mp4"), true);

But for some reason, this fails every time I try it, and I have tested the video I am testing with using https://github.com/twitterdev/large-video-upload-python and it works I did ask for help on twitter forums before confirming it is a problem with this library.
https://twittercommunity.com/t/media-upload-rejecting-mp4-videos/104181

Oh and just a note on that note when uploading an image when I'm calling and it works perfectly...


$s3Path = $imagePath = "https://s3-eu-west-1.amazonaws.com/beacon.media/".($media->path);
$tmpPath = sys_get_temp_dir()."/".sha1(time()."_".microtime());
$fh = fopen($tmpPath, "w");
fwrite($fh, $s3->download($media->path));
fclose($fh);
		
$response = $this->getConnection()->upload("media/upload", array("media" => $tmpPath));
@barkermn01

This comment has been minimized.

barkermn01 commented Apr 18, 2018

Complete overhaul of this post as I have even more debugging: and some major evidence that some stuff is going wrong a twitter: but I think I have now found out it also ties in the issue: #625

private function uploadMediaChunked($path, array $parameters)
    {
        $initParams = $this->mediaInitParameters($parameters);
        $init = $this->http('POST', self::UPLOAD_HOST, $path, $initParams);
        // Append
        $segmentIndex = 0;
        $media = fopen($parameters['media'], 'rb');
        $totalSegmants = ceil($initParams['total_bytes']/$this->chunkSize);
        $totalSent = 0;
        while (!feof($media))
        {
            $bin = fread($media, $this->chunkSize);
            error_log("segment ".($segmentIndex+1)."/{$totalSegmants} is of size ".strlen($bin)." bytes ");
            $this->http('POST', self::UPLOAD_HOST, 'media/upload', [
                'command' => 'APPEND',
                'media_id' => $init->media_id_string,
                'segment_index' => $segmentIndex++,
                'media' => $bin
            ]);
            $totalSent += strlen($bin);
            error_log("sent {$totalSent}/{$initParams['total_bytes']}");
        }
        fclose($media);
        // Finalize
        $finalize = $this->http('POST', self::UPLOAD_HOST, 'media/upload', [
            'command' => 'FINALIZE',
            'media_id' => $init->media_id_string
        ]);

        //check media is ready
        while(true){
                error_log("sending STATUS requet for {$init->media_id_string}");
                $data = $this->http('POST', self::UPLOAD_HOST, 'media/upload', [
                        'command' => 'STATUS',
                        'media_id' => $init->media_id_string,
                ]);
                error_log("state = ".json_encode($data));
                if($data->processing_info->state != 'in_progress'){
                        if($data->processing_info->state == "failed"){
                                error_log("failed to upload media to twitter {$data->processing_info->error->message}");
                                throw new \Exception("Upload media to twitter failed \r\n {$data->processing_info->error->message}");
                        }
                        break;
                }
                if(isset($data->processing_info)){
                        sleep($data->processing_info->check_after_secs);
                }
        }
        return $finalize;
    }

As you can see there is a whole load of debugging added in I have also changed it to use binary media and not media_data as base64 (this was for testing purposes).

So far all I'm seem to be getting is more code evidence that this is a Twitter API error while I have the forum post open from them I will leave this open but if it turns out I don't need to fix anything in this code base from them I will close this ticket, if I do I will push a fix once it is confirmed what is going wrong.

But the latest evidence shows a couple of problems with twitters API the first is telling me an attribute is required when it is not according to the documentation (from below state = {"errors":[{"code":38,"message":"media parameter is missing."}]}) Documentation here

and the {"request":"\\/1.1\\/media\\/upload.json","error":"Segments do not add up to provided total file size."} (from below) after all the totals being added up show twitter is just wrong about this aswell. it all sums up correctly. you can see more about this based on my last set of debugging on the post: https://twittercommunity.com/t/media-upload-rejecting-mp4-videos/104181/6

And the output provided:

[Wed Apr 18 12:34:02.996705 2018] [php7:notice] [pid 27159] [client 172.31.32.224:31699] File /tmp/f54897f638f4614f6232fb4ec35dece8479813e7_d470686180bd7bb6a4b8591b364dd7f73b14caf9.mp4 size is 1446304 bytes, referer: *OMITTED*
[Wed Apr 18 12:34:03.234387 2018] [php7:notice] [pid 27159] [client 172.31.32.224:31699] segment 1/6 is of size 250000 bytes , referer: *OMITTED*
[Wed Apr 18 12:34:05.419806 2018] [php7:notice] [pid 27159] [client 172.31.32.224:31699] sent 250000/1446304, referer: *OMITTED*
[Wed Apr 18 12:34:05.421065 2018] [php7:notice] [pid 27159] [client 172.31.32.224:31699] segment 2/6 is of size 250000 bytes , referer: *OMITTED*
[Wed Apr 18 12:34:07.655178 2018] [php7:notice] [pid 27159] [client 172.31.32.224:31699] sent 500000/1446304, referer: *OMITTED*
[Wed Apr 18 12:34:07.655411 2018] [php7:notice] [pid 27159] [client 172.31.32.224:31699] segment 3/6 is of size 250000 bytes , referer: *OMITTED*
[Wed Apr 18 12:34:09.794782 2018] [php7:notice] [pid 27159] [client 172.31.32.224:31699] sent 750000/1446304, referer: *OMITTED*
[Wed Apr 18 12:34:09.795031 2018] [php7:notice] [pid 27159] [client 172.31.32.224:31699] segment 4/6 is of size 250000 bytes , referer: *OMITTED*
[Wed Apr 18 12:34:12.012933 2018] [php7:notice] [pid 27159] [client 172.31.32.224:31699] sent 1000000/1446304, referer: *OMITTED*
[Wed Apr 18 12:34:12.013173 2018] [php7:notice] [pid 27159] [client 172.31.32.224:31699] segment 5/6 is of size 250000 bytes , referer: *OMITTED*
[Wed Apr 18 12:34:14.195218 2018] [php7:notice] [pid 27159] [client 172.31.32.224:31699] sent 1250000/1446304, referer: *OMITTED*
[Wed Apr 18 12:34:14.195435 2018] [php7:notice] [pid 27159] [client 172.31.32.224:31699] segment 6/6 is of size 196304 bytes , referer: *OMITTED*
[Wed Apr 18 12:34:15.930540 2018] [php7:notice] [pid 27159] [client 172.31.32.224:31699] sent 1446304/1446304, referer: *OMITTED*
[Wed Apr 18 12:34:16.201088 2018] [php7:notice] [pid 27159] [client 172.31.32.224:31699] sending STATUS requet for 986583635326324737, referer: *OMITTED*
[Wed Apr 18 12:34:16.405301 2018] [php7:notice] [pid 27159] [client 172.31.32.224:31699] state = {"errors":[{"code":38,"message":"media parameter is missing."}]}, referer: *OMITTED*
[Wed Apr 18 12:34:16.405453 2018] [php7:notice] [pid 27159] [client 172.31.32.224:31699] {"request":"\\/1.1\\/media\\/upload.json","error":"Segments do not add up to provided total file size."}, referer: *OMITTED*

@abraham abraham closed this Jul 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment