загрузка видео в облачное хранилище Google с использованием титана - PullRequest
0 голосов
/ 05 июня 2018

Я использую Appcelerator для создания приложений.Я застрял в ситуации, когда я хочу загрузить записанное видео из моего приложения в Google Cloud Storage.Мы искали SDK или модули облачного хранилища Google для загрузки, но мы не смогли найти много.Я попробовал несколько методов, поскольку я исследовал

Метод 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:'API KEY' });

Ответ: -

   {
   "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."}
  }

Метод 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();

Ответ: - devstorage.full_control

Метод 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": {
    "errno": -4058,
    "code": "ENOENT",
    "syscall": "stat",
    "path": "C:\Sites\Api\test\\file:\\\storage\\emulated\0\Pictures\\test-966434132.mp4"
  },
    "status": 2
}

Пожалуйста, помогите мне в этой ситуации, я очень новичокк этому.Заранее спасибо.

1 Ответ

0 голосов
/ 05 июня 2018

Я выполнил поиск и не смог найти ни одной библиотеки, написанной специально для Titanium, для загрузки в Google Cloud Storage.

Таким образом, у вас в основном есть 2 варианта:

Первый - взять нативныйклиентскую библиотеку (официальную или ту, что кто-то уже написал) и оберните ее модулем Titanium.Вы можете найти клиентские библиотеки здесь (https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-java)

. Второй вариант - сделать вызовы непосредственно в облачное хранилище json api самостоятельно. Документацию по API можно найти здесь: https://cloud.google.com/storage/docs/json_api/, и вам потребуетсяреализовать http-вызовы к нему с помощью кода Titanium (https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Network.HTTPClient).

Для простоты использования при написании http API я рекомендую использовать библиотеку RESTe Джейсона Кина (https://github.com/jasonkneen/RESTe)

...