【问题标题】:How to get raw image from a public url?如何从公共网址获取原始图像?
【发布时间】:2021-05-06 16:24:00
【问题描述】:

我试图在节点中使用 Google Drive API 托管图像。

await drive.files.create({
  requestBody: {
    role: "render",
    type: "anyone",
  },
});

const response = await drive.files.get({
  fileId: "...",
  fields: "webViewLink, webContentLink",
});

console.log(response.data);

我获得了一个图片的公共链接,我可以在 Google 云端硬盘中打开或下载该图片以便手动查看。

{
  webContentLink: 'https://drive.google.com/uc?id=1dffGf_4R5W75xKGhx7n-nXsZPFA7NE1a&export=download',
  webViewLink: 'https://drive.google.com/file/d/1dffGf_4R5W75xKGhx7n-nXsZPFA7NE1a/view?usp=drivesdk' 
}

但这不是我想要的。

我希望公共图像为原始格式(jpg、png 等),并且应该能够像浏览器中的网站一样正常查看。

我希望我已经解释得够多了,非常感谢任何帮助:)

【问题讨论】:

  • 很遗憾,我无法从But this is not what I want. I want the public images to be in raw format (jpg, png, etc.) and should be able to be viewed normally like a website in the browser. 了解您当前的问题。我为我糟糕的英语水平深表歉意。为了正确理解您的问题,您能否提供当前问题的详细信息和您的目标?
  • 你不能得到这个。但是,作为一种解决方法,如果您想将图像嵌入到网页中,您可以使用预览链接stackoverflow.com/a/62571215/11551468
  • Google Drive 是一个文件存储系统,而不是一个虚拟主机站点。

标签: node.js image google-drive-api


【解决方案1】:

我刚刚发现不是这个...

https://drive.google.com/file/d/1-x3h_1lYrBat7K43LaiTlS9FqQttbbFW/view?usp=sharing

我可以传递缩略图,然后像这样传递 file id...

https://drive.google.com/thumbnail?id=1-x3h_1lYrBat7K43LaiTlS9FqQttbbFW

这很好用,可以嵌入到img 标记的src 属性中... (source)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-06
    • 1970-01-01
    相关资源
    最近更新 更多