那么:我如何使用驱动器按钮:https://developers.google.com/drive/v3/web/savetodrive并从输入:文件加载选定的本地文件,以便将其保存在云端?
据我所知,该按钮通过将其url放在按钮中来加载托管在另一台主机上的文件,但我需要保存一个本地文件,并从" input:file"把它放在" data-url"或上传文件的正确位置(在我的情况下是图像)
<!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"
onChange="renderSaveToDrive('savetodrive-div', this.files[0].name,'GDrive');">
<div id="savetodrive-div"></div>
</form>
<script>
function renderSaveToDrive(namediv, namefile, idfrm) {
console.log('namediv: ' + namediv + ' nameFile: ' + namefile);
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>
&#13;