使用Dart在Google云端硬盘上阅读文件

时间:2014-05-01 17:41:56

标签: dart google-drive-api

我在Google云端硬盘上创建了一个配置文件(简单文本文件),现在我想从我的Chrome Packaged Dart应用程序中读取它。但是我无法获得有关该文件的更多信息,而不是它的名称,大小等。

要访问Google云端硬盘,请使用 google_drive_v2_api

有关如何获取配置文件内容的任何建议都会很棒!谢谢!

2 个答案:

答案 0 :(得分:2)

我刚在自己的Chrome应用中进行了一些测试,上传并下载了一个简单的文件:

 chrome.identity.getAuthToken(new chrome.TokenDetails(interactive: true ))
.then((token){
   OAuth2 auth = new SimpleOAuth2(token);
   var drive = new gdrive.Drive(auth)..makeAuthRequests=true;
   drive.files.insert({},content:window.btoa('hello drive!')).then((sentMeta){

      print("File sent! Now retrieving...");

      drive.files.get(sentMeta.id).then((repliedMeta){
      HttpRequest request = new HttpRequest()..open('GET', repliedMeta.downloadUrl)
        ..onLoad.listen((r)=>print('here is the result:'+r.target.responseText));
      auth.authenticate(request).then((oAuthReq)=>oAuthReq.send());
    });
  });
});

它有效,但获取内容的HttpRequest似乎很重......

但是如果你的配置文件大小是<

我真的建议你去看看 chrome.storage.sync 。 to 4ko ...如果没有,你也可以使用chrome SyncFileSystem API ...它们更容易使用,而SyncFileSystem使用Drive作为后端。

答案 1 :(得分:0)

downloading files上的这个页面讨论了获取文件内容的过程。