2014-07-01 50 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>