在网站上,用户可以上传音乐。此音乐正在上传到我的 Google Drive 帐户中。之后,将以下链接格式写入数据库:
https://drive.google.com/uc?id=ID_GOES_HERE
现在,当您访问链接时,它会发生如下变化:
https://doc-14-8s-docs.googleusercontent.com/docs/securesc/m4p0h6h3bpkoufgbajruvng9n4f51clu/fnjf7ftnl18svtcblses77hapi91jpe5/1597565925000/10139445714759083419/10139445714759083419/1mLu_myEgts9eaoWv6S9nxu8n4qfZM0Rr?authuser=0
长链接是数据库中用于应用程序播放音乐的链接,但我没有权限再在那里打开它。如何使最后一个长链接可访问?有没有办法让这个长链接公开?
谢谢!
<form id="form">
<input name="file" id="uploadfile" type="file">
<input name="filename" id="filename" type="text">
<input id="submit" type="submit">
</form>
<script>
const form = document.getElementById('form');
form.addEventListener('submit', e => {
e.preventDefault();
const file = form.file.files[0];
const fr = new FileReader();
fr.readAsArrayBuffer(file);
fr.onload = f => {
const url = "https://script.google.com/macros/s/###/exec"; // <--- Please set the URL of Web Apps.
const qs = new URLSearchParams({filename: form.filename.value || file.name, mimeType: file.type});
fetch(`${url}?${qs}`, {method: "POST", body: JSON.stringify([...new Int8Array(f.target.result)])})
.then(res => res.json())
.then(e => console.log("https://drive.google.com/uc? export=download&id=" + e.fileId))
.catch(err => console.log(err));
}
});
</script>
这是谷歌应用脚本
function doPost(e) {
const folderId = "root"; // Folder ID which is used for putting the file, if you need.
const blob = Utilities.newBlob(JSON.parse(e.postData.contents), e.parameter.mimeType, e.parameter.filename);
const file = DriveApp.getFolderById(folderId || "root").createFile(blob);
const responseObj = {filename: file.getName(), fileId: file.getId(), fileUrl: file.getUrl()};
return ContentService.createTextOutput(JSON.stringify(responseObj )).setMimeType(ContentService.MimeType.JSON);
}
- - - - 编辑 - - - -
我尝试了给定的解决方案:
可悲的是它没有按预期工作..我得到以下链接:
https://drive.google.com/uc?export=download&id=1Tnh8UgAzFKrp6e-8QCl21v16L3yVCqso
现在,当我从中获取 id 并将其插入此处时:
http://docs.google.com/uc?export=open&id=your_file_id
结果是一个非常长的链接,这是我需要的链接。例如,如果我在私人浏览器模式下仍然无法访问这个,它会强制我登录我不想要的。它应该可以通过您的解决方案中的链接访问。这是链接:
https://doc-08-8s-docs.googleusercontent.com/docs/securesc/m4p0h6h3bpkoufgbajruvng9n4f51clu/cgag5dus6c18p9hc1hv0362urudm2g6t/1597730475000/10139445714759083419/10139445714759083419/1Tnh8UgAzFKrp6e-8QCl21v16L3yVCqso?e=open&authuser=0
如何使此链接可访问?
似乎此链接具有您设置的权限http://docs.google.com/uc?export=open&id=your_file_id但如果您复制长链接,此链接不提供权限设置,它仍然会阻止。