File upload 视频上传到谷歌云存储使用钛

File upload 视频上传到谷歌云存储使用钛,file-upload,titanium,google-cloud-storage,appcelerator,hybrid-mobile-app,File Upload,Titanium,Google Cloud Storage,Appcelerator,Hybrid Mobile App,我正在使用Appcelerator构建应用程序。我陷入了这样的境地:我想将我的应用程序录制的视频上传到谷歌云存储。我们正在寻找用于上传的谷歌云存储sdk或模块,但我们找不到太多。我在研究中尝试了几种方法 方法1: var dataUri = event.media.nativePath; Titanium.Media.saveToPhotoGallery(dataUri); xhr.onload = function(e) { Ti.API.info('onload:- ' + JSON.str

我正在使用Appcelerator构建应用程序。我陷入了这样的境地:我想将我的应用程序录制的视频上传到谷歌云存储。我们正在寻找用于上传的谷歌云存储sdk或模块,但我们找不到太多。我在研究中尝试了几种方法

方法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\u控制

方法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
}

在这种情况下,请帮助我,我对这种情况很陌生。提前谢谢。

我搜索了一下,没有找到任何专门用钛合金编写的库,可以上传到谷歌云存储

所以你基本上有两个选择:

第一种方法是使用一个本地客户端库(官方的或已经有人编写过的)并用钛模块包装它。您可以在此处找到客户端库()

第二种选择是自己直接调用云存储json api。API文档可以在这里找到:您需要使用Tianium代码()实现对它的http调用

为了便于编写http API,我建议使用Jason Keen的RESTe库()