简体   繁体   English

如何从公共 url 获取原始图像?

[英]How to get raw image from a public url?

I was trying to host an image with Google Drive API in node.我试图在节点中使用 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);

I was getting a public link to the image which I can open inside Google Drive or download to be able to view it manually.我得到了一个图片的公共链接,我可以在 Google Drive 中打开或下载该图片以便手动查看。

{
  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' 
}

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.我希望公共图像采用原始格式(jpg、png 等),并且应该能够像浏览器中的网站一样正常查看。

I hope I've explained it enough, any help is really appreciated:)我希望我已经解释得足够多了,任何帮助都非常感谢:)

I just found that instead of this...我只是发现,而不是这个......

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

I could pass pass thumbnail followed by the file id like this...我可以传递缩略图,然后是这样的file id ......

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

This works well and could be embedded into the src attribute of the img tag... ( source ).这很好用,可以嵌入到img标签的src属性中......( 来源)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM