Uploading video to youtube fails

171 views
Skip to first unread message

Rocco Bruyn

unread,
Aug 23, 2013, 7:12:07 AM8/23/13
to phon...@googlegroups.com
Hi all,

I'm not sure this is a phonegap problem per-se, but it's were i'm experiencing the problem so here goes.

I'm trying to upload a recorded video to youtube. This worked previously, but seems to have stopped doing so since upgrading to Cordova 3, although i'm fairly sure there's more to it than just that.

The process is roughly as follows:

  1. User records video
  2. Path to video is stored in local sqlite DB
  3. When user hit 'upload' an upload token is requested via ajax
  4. On success the token is used to upload the actual video
  5. Youtube (supposedly) redirects after a successful upload to a given url (our api server) to inform it of the successful upload accompanied by the generated videoid
  6. All goes well until the last step. I can see it uploading until all the bytes are sent, but then it seems to get a timeout on the redirect. Which is weird because when i request the same url through a browser it responds immediately.

The error/exception it get is:

...
08-22 14:47:40.062: D/FileTransfer(18610): Uploaded 4244149 of 4244236 bytes
08-22 14:47:40.175: D/FileTransfer(18610): Sent 4244236 of 4244236
08-22 14:47:40.972: D/dalvikvm(18610): GC_CONCURRENT freed 425K, 52% free 3674K/7584K, paused 5ms+9ms, total 36ms
08-22 14:47:51.273: D/FileTransfer(18610): response code: 408
08-22 14:47:51.285: D/FileTransfer(18610): response headers: {null=[HTTP/1.1 408 Request Time-out], Connection=[close], Content-Type=[text/html; charset=iso-8859-1], Date=[Thu, 22 Aug 2013 12:47:39 GMT], Server=[Apache/2.2.22 (Ubuntu)], Vary=[Accept-Encoding], X-Android-Received-Millis=[1377175671277], X-Android-Response-Source=[NETWORK 408], X-Android-Sent-Millis=[1377175660994]}
08-22 14:47:51.328: E/FileTransfer(18610): {"target":"https:\/\/uploads.gdata.youtube.com\/action\/FormDataUpload\/AIwbFAQAYYTiD3JfA0A9Q4qxu_tR8TyWs1lbQ2J1mWUCvBSjOA2kxkWhZ_7LMzhk2Laiz4L7DPUXPzs5brw_dnFX8IP2xVzg6w?nexturl=http:\/\/api.office.smoovz.com\/v1\/status\/feedback","http_status":408,"body":"<!DOCTYPE HTML PUBLIC \"-\/\/IETF\/\/DTD HTML 2.0\/\/EN\">\n<html><head>\n<title>408 Request Time-out<\/title>\n<\/head><body>\n<h1>Request Time-out<\/h1>\n<p>Server timeout waiting for the HTTP request from the client.<\/p>\n<hr>\n<address>Apache\/2.2.22 (Ubuntu) Server at api.office.smoovz.com Port 80<\/address>\n<\/body><\/html>","code":1,"source":"file:\/\/\/storage\/sdcard0\/DCIM\/Camera\/VID_20130821_155514.mp4"}
08-22 14:47:51.328: E/FileTransfer(18610): java.io.FileNotFoundException: http://api.office.smoovz.com/v1/status/feedback?status=200&id=XXXXXXXXX
08-22 14:47:51.328: E/FileTransfer(18610):  at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:224)
08-22 14:47:51.328: E/FileTransfer(18610):  at com.squareup.okhttp.internal.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:285)
08-22 14:47:51.328: E/FileTransfer(18610):  at org.apache.cordova.core.FileTransfer.getInputStream(FileTransfer.java:527)
08-22 14:47:51.328: E/FileTransfer(18610):  at org.apache.cordova.core.FileTransfer.access$5(FileTransfer.java:522)
08-22 14:47:51.328: E/FileTransfer(18610):  at org.apache.cordova.core.FileTransfer$3.run(FileTransfer.java:448)
08-22 14:47:51.328: E/FileTransfer(18610):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
08-22 14:47:51.328: E/FileTransfer(18610):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
08-22 14:47:51.328: E/FileTransfer(18610):  at java.lang.Thread.run(Thread.java:856)
08-22 14:47:51.343: I/Web Console(18610): Failed to upload video. Error:  (code  = 1) (source  = file:///storage/sdcard0/DCIM/Camera/VID_20130821_155514.mp4) (target  = https://uploads.gdata.youtube.com/action/FormDataUpload/AIwbFAQAYYTiD3JfA0A9Q4qxu_tR8TyWs1lbQ2J1mWUCvBSjOA2kxkWhZ_7LMzhk2Laiz4L7DPUXPzs5brw_dnFX8IP2xVzg6w?nexturl=http://api.office.smoovz.com/v1/status/feedback) (http_status  = 408) (body  = <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
08-22 14:47:51.343: I/Web Console(18610): <html><head>
08-22 14:47:51.343: I/Web Console(18610): <title>408 Request Time-out</title>
08-22 14:47:51.343: I/
Web Console(18610): </head><body>
08-22 14:47:51.343: I/
Web Console(18610): <h1>Request Time-out</h1>
08-22 14:47:51.343: I/
Web Console(18610): <p>Server timeout waiting for the HTTP request from the client.</p>
08-22 14:47:51.343: I/Web Console(18610): <hr>
08-22 14:47:51.343: I/Web Console(18610): <address>Apache/2.2.22 (Ubuntu) Server at api.office.smoovz.com Port 80</address>
08-22 14:47:51.343: I/
Web Console(18610): </body></html>) at file:///android_asset/www/js/app/debug.js:18
...



If i look in the apache logs on the api server it says "Error reading first chunk". I've tried to google this, but it doesn't give me much to go on. Turning off chunked mode for the file transfer seems to help, but i don't want that as videos can get quite large and besides that i feel that is should work. I just can't seem to figure out why it doesn't..

Anyone any ideas?

Michael Bell

unread,
Apr 3, 2015, 9:39:22 AM4/3/15
to phon...@googlegroups.com
Hi,

I am in a similar predicament, with an almost identical setup.

Can I ask if you resolved this and if so what kind of data did you send to youtube? I can send a blob but if the file is over 15MB there is an exception. 
Any help with be appreciated.

I am using a FileReader at present. See below

 function success(data){
 var reader = new FileReader();
                    reader.onloadend = function (evt) {
                        var contentType = 'video/mp4';
                        // var blob = b64toBlob(evt.target.result.replace(/^data.*base64,/, ''), contentType);

                        // var blob = b64toBlobAlt(evt.target.result, contentType);
                        console.log(evt)
                        // debugger;
                        $this.uploadFile( evt.target.result.replace(/^data.*base64,/, '') );
                    };
                    reader.readAsDataURL(data);
                }
...

Osman Tekin

unread,
Apr 3, 2015, 10:25:07 AM4/3/15
to phon...@googlegroups.com
Can you show the exception?

Osman Tekin

unread,
Apr 3, 2015, 10:27:22 AM4/3/15
to phon...@googlegroups.com
I'm not sure, but it looks like an issue with the server, specifically http://api.office.smoovz.com/v1/status/feedback?status=200&id=XXXXXXXXX I would first make sure it's actually reachable.
...

Michael Bell

unread,
Apr 13, 2015, 4:10:56 PM4/13/15
to phon...@googlegroups.com
I'm getting this:

"{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Required parameter: part",
    "locationType": "parameter",
    "location": "part"
   }
  ],
  "code": 400,
  "message": "Required parameter: part"
 }
}"


And here is my new test:
var metadata = {
                    snippet: {
                        title: "test",
                        description: "test",
                        tags: ["youtube-cors-upload"],
                        categoryId: 21
                    },
                    status: {
                        privacyStatus: "unlisted"
                    }
                };

                var options = new FileUploadOptions();
                options.fileKey = "file";
                options.fileName = 'test';
                options.mimeType = "video/mp4";
                options.httpMethod = "POST"

                options.headers = {
                    Authorization: "Bearer "+ accessToken};
                }
                var params = new Object();
                params.part = Object.keys(metadata).join(',')

                options.params = params;
                console.log(options)
                debugger;
                var ft = new FileTransfer();
                ft.upload(fileURI, "https://www.googleapis.com/upload/youtube/v3/videos", win, fail, options);

                ft.onprogress = function(progressEvent) {
                    if (progressEvent.lengthComputable) {
                        // console.log(progressEvent)
                      // loadingStatus.setPercentage(progressEvent.loaded / progressEvent.total);
                    } else {
                        console.log('something not loading')
                      // loadingStatus.increment();
                    }
                    // console.log(progressEvent.loaded / progressEvent.total);
                  };

Jesse Monroy

unread,
Apr 25, 2015, 7:44:15 PM4/25/15
to phon...@googlegroups.com
Guys,
the original post is over one (1) year old (posted on 8/23/13). Date is on the top right.

Start a new thread. Post a better details explanation.

Jesse


Reply all
Reply to author
Forward
0 new messages