I created a configuration file (Simple Text File) on my Google Drive and now I would like to read it from my Chrome Packaged Dart Application. But I'm not able to get more information of the file than it's name, size etc.

For accessing Google Drive I use the google_drive_v2_api.

Any suggestion on how to get the contents of my configuration file would be great! Thanks!

有帮助吗?

解决方案

I just did some test in my own chrome app, uploading and downloading a simple file:

 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());
    });
  });
});

It works, but the HttpRequest to get content back seems heavy...

But i really recommend you to a take look to chrome.storage.sync if your config file size is < to 4ko... If not, you could also use the chrome SyncFileSystem API... They are both easier to use, and SyncFileSystem use Drive as backend.

其他提示

This page on downloading files talks through the process for getting the contents of a file.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top