img src=webContentLink 中的 Google Drive 图片? [英] Google Drive images in img src=webContentLink?

查看:20
本文介绍了img src=webContentLink 中的 Google Drive 图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用存储在 Google Drive 中的图像通过 html 在网站中使用吗,<img src="<webContentLink>"/> ?

其中 <webContentLink> 在文件上传后返回,格式为 '

webContentLink 可以使用 Files.list 并将文件"放在 fields 参数中.

Can I use images stored in Google Drive to be used in a website by the html,<img src="<webContentLink>" /> ?

Where <webContentLink> is returned after a file is uploaded and is in the format, 'https://drive.google.com/uc?id=<FILEID>&export=download'

I have a small website created for account users only. They can upload files to their google drive folder and this folder has permissions set to share with the accounts of the other users (specific people only). This is an ASP.NET MVC 5 website using the Google API Client Libraries for .NET.

In Chrome and Firefox the images display fine, in IE and Safari they don't show and return a 302 status code. Sometimes if you view the image directly in a new tab and then refresh the web page it shows. It might also show if the folder permission is set to 'anyone with the link', but this isn't ideal.

The documentation (https://developers.google.com/drive/v3/web/manage-downloads) says, 'If you want to allow a user to view a file directly in a web browser instead of through the API, use the webContentLink.' I understood this to be okay to use img src='' to display an image directly without the API, however it then goes on to say, 'You can either redirect a user to this URL, or offer it as a clickable link'.

So can Google please confirm if 'webContentLink' can be used in img src='', or not and why it works in some browsers and not others? I've read many posts on this, some old, some more recent. If it's not to be used in img src I think it should be made clear in the documentation.

Many thanks

解决方案

Yes, you can definitely use webContentLink as your img src in your HTML page. I tried and this is what I got on my sample HTML page.

  <img src = "https://drive.google.com/uc?id=0Bzgk4zncCwI7aDZCSHY4YU0zNUF&export=download">

webContentLink can be obtained using Files.list and place 'files' in the fields parameter.

这篇关于img src=webContentLink 中的 Google Drive 图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆