2014-07-01 46 views
0

我试图做一个网站,将节省猫存入该帐户的用户,并曾经尝试​​这样做:谷歌驱动器保存到不工作(谷歌驱动API)

<script src="https://apis.google.com/js/platform.js"></script> 
<div class="g-savetodrive" 
    data-src="http://example.com/pug-snores.mp3" 
    data-filename="pug-snores.mp3" 
    data-sitename="A Snoring Pug"> 
</div> 

保存图标显示出来,但它不保存到驱动器。

为什么?

感谢

+0

看到https://developers.google.com/drive/web/savetodrive#cors –

+0

否则有什么不对的文件路径 - 这也将导致此错误 –

+0

它仍然没有按” t工作地址= http://samrobbins.125mb.com/googledrive.html – samrobbins

回答

0

尝试明确渲染:代码从google javascript api

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Save to Drive Demo: Explicit Render</title> 
    <link rel="canonical" href="http://www.example.com"> 
    <script src="https://apis.google.com/js/platform.js"> 
     {parsetags: 'explicit'} 
    </script> 
    </head> 
    <body> 
    <a href="javascript:void(0)" id="render-link">Render the Save to Drive button</a> 
    <div id="savetodrive-div"></div> 
    <script> 
     function renderSaveToDrive() { 
     gapi.savetodrive.render('savetodrive-div', { 
      src: '//example.com/path/to/myfile.pdf', 
      filename: 'My Statement.pdf', 
      sitename: 'My Company Name' 
     }); 
     } 
     document.getElementById('render-link').addEventListener('click', renderSaveToDrive); 
    </script> 
    </body> 
</html> 

数据-src网址可以从另一个域服务,但来自HTTP服务器的响应需要支持HTTP OPTION请求,包括以下几个特殊的HTTP标头:

Access-Control-Allow-Origin: * 
Access-Control-Allow-Headers: Range 
Access-Control-Expose-Headers: Cache-Control, Content-Encoding, Content-Range 
+0

是文件损坏? –

+0

我需要在example.com附近放置什么? – samrobbins

+0

@Sam你自己的网址 –

0

如果你想上传的输入文件形式的本地文件和/或不PHP LIB w ^乌尔德是...

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Save to Drive Demo: Explicit Render</title> 
    <script src="https://apis.google.com/js/platform.js" async defer></script> 
    </head> 
    <body> 
    <form id="GDrive" name="GDrive" enctype="multipart/form-data" method = "post"> 
     <input type="file" id="file" name="file" onChange="renderSaveToDrive('savetodrive-div', this.files[0].name,'GDrive');"><div id="savetodrive-div"></div> 
    </form> 
    <script> 
     function renderSaveToDrive(namediv, namefile, idfrm) { 
      window.___gcfg = { 
       lang: 'es-ES', 
       parsetags: 'explicit' 
      }; 
      var xhr = new XMLHttpRequest(); 
      var fd = new FormData(document.forms.namedItem(idfrm)); 
      fd.append("file_new_name", namefile); 
      xhr.open("POST", location.href); 
      xhr.send(fd);  
      gapi.savetodrive.render(namediv, { 
       src: namefile, 
       filename: namefile, 
       sitename: 'GDrive Demo: Explicit Render' 
      }); 
     } 
    </script> 
    </body> 
</html>