upload video to google cloud storage from appcelerator titanium app

70 views
Skip to first unread message

Kiran Jadhav

unread,
Jun 9, 2018, 12:14:27 PM6/9/18
to Google Cloud Developers

   I am using Appcelerator for building apps. I stuck in the situation in which I want to upload recorded video from my app to Google Cloud Storage. We were looking for google cloud storage sdk or modules to use to upload, but we couldn't find much. I've tried several methods as I've researched

Method 1:

var dataUri = event.media.nativePath;

Titanium.Media.saveToPhotoGallery(dataUri);

 xhr.onload = function(e) {

 Ti.API.info('onload:- ' + JSON.stringify(this.responseText));

 };

 

 xhr.onerror = function(e) {

 Ti.API.info('onerror:- ' + JSON.stringify(this.responseText));

 };

 

 xhr.onsendstream = function(e) {

 Ti.API.info('math:- ' + Math.floor(e.progress * 100) + "%");

 };

xhr.open('GET', 'https://www.googleapis.com/storage/v1/b/bucket_name/o?’);

 

 xhr.onsendstream = function(e) {

 Ti.API.info('math:- ' + Math.floor(e.progress * 100) + "%");

 };

xhr.send({

 file : dataUri,

 key:'AIzaSyB558w5P9A1ftWfjSekdCJdWCI17bZwetM'

 });


Result Found :

Response :- {

"error": {

"errors": [{

"domain": "usageLimits",

"reason": "ipRefererBlocked",

"message": "There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed.",

"extendedHelp": "https://cosole.developers.google.com"

}],

"code": 403,

"message": "There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed."

}

}


Method 2:


var dataUri = event.media.nativePath;

Titanium.Media.saveToPhotoGallery(dataUri);

 xhr.onload = function(e) {

 Ti.API.info('onload:- ' + JSON.stringify(this.responseText));

 };

 

 xhr.onerror = function(e) {

     Ti.API.info('onerror:- ' + JSON.stringify(this.responseText));

 };

 

 xhr.onsendstream = function(e) {

 Ti.API.info('math:- ' + Math.floor(e.progress * 100) + "%");

 };


var REQUEST_URL = "https://www.googleapis.com/auth/devstorage.full_control"; 

  xhr.open("GET", REQUEST_URL);

  xhr.onsendstream = function(e) {

  Ti.API.info('math:- ' + Math.floor(e.progress * 100) + "%");

 };

 xhr.send();


Result Found :

Response :- devstorage.full_control



Method 3:


var dataUri = event.media.nativePath;

Titanium.Media.saveToPhotoGallery(dataUri);


var xhr = Titanium.Network.createHTTPClient({

  enableKeepAlive : false

});


xhr.send({

video : dataUri

});


xhr.setRequestHeader("enctype", "multipart/form-data");

xhr.setRequestHeader('Cache-Control', 'no-cache');

xhr.onerror = function(e) {

  alert(e.error);

};

xhr.onload = function() {

var data = JSON.parse(this.responseText);

if (data.FILE)

  alert('File: ' + data.FILE);

else

  alert(this.responseText);

};

xhr.open('GET', ‘ipaddress/api_file/api_name’);

xhr.send();


Result Found :

Response :- {

"result": {

"errno": -4058,

"code": "ENOENT",

"syscall": "stat",

"path": "C:\Sites\Api\test\\file:\\\storage\\emulated\0\Pictures\\test-966434132.mp4"

},

"status": 2

}









Kindly help me in this situation, I am very new to this. Thanks in advance.

George (Cloud Platform Support)

unread,
Jun 9, 2018, 1:49:02 PM6/9/18
to Google Cloud Developers
Documentation explains how to upload files to your Cloud Storage bucket. On the "Uploading Objects" documentation page, you may find samples of node.js code that you may adapt to your Appcelerator needs. You should choose the "code samples" tab, and then "node.js". 

This discussion group is oriented more towards general opinions, trends and issues of general nature touching the app engine. For coding and programming architecture, you may be better served in a forum such as stackoverflow, where experienced programmers are within reach and ready to help. 

Reply all
Reply to author
Forward
0 new messages