这是一个简单的例子:
问题:您通过共享 google 驱动器图像获得的图像 url 将是这样的
简单的解决方案:
(**a) https://drive.google.com/file/d/{this 部分将包含我们需要的图像 ID}/view?usp=sharing
但是要使用图片,我们需要这样的 url
(**b) https://drive.google.com/uc?id={this 部分将包含我们需要的图像 ID}
所以我们可以做的简单的事情是从 (**a) url 手动复制图像 ID 的那部分并粘贴到 (**b) url。
使用 JavaScript 自动化:
let sharableLink = (**a); //paste the google drive image sharing link here
let baseUrl = "https://drive.google.com/uc?id=";
let imageId = sharableLink.substr(32, 33); //this will extract the image ID from the shared image link
let url = baseUrl.concat(imageId); //this will put the extracted image id to end of base Url
这里的 32 和 33 是要从共享图片链接中提取的图片 ID 的开始和结束位置。
插件:
您可以创建一个简单的 HTML 来从共享链接中获取转换后的图像 Url。
HTML:
sample.html
<!DOCTYPE html>
<html>
<head>
<body>
</div>
<!-- container for url and button to load it -->
<div class="thumbnail-container">
<input
type="text"
id="edt-thumbnail-url"
name="thumbnail-url"
placeholder="Thumbnail Url">
<div>
<button class="btn btn-load-thumbnail" id="btn-load-thumbnail">Upload Thumbnail</button>
</div>
</div>
<!-- script that runs the code for conversion -->
<script src="/sample.js"></script>
</body>
<head>
</html>
现在创建一个 javascript 文件并粘贴它
sample.js
const productThumbnailUrl = document.getElementById("edt-thumbnail-url");
const btnUploadThumbnail = document.getElementById("btn-load-thumbnail");
btnUploadThumbnail.addEventListener("click", (e) => {
e.preventDefault();
let str = productThumbnailUrl.value;
let baseUrl = "https://drive.google.com/uc?id=";
let imageId = str.substr(32, 33);
let url = baseUrl.concat(imageId);
productThumbnailUrl.value = url; //this will put the converted url in the edit text box
console.log(url);
});