Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
896 views
in Technique[技术] by (71.8m points)

html - How to use <img src > in google apps script

I want to display the image in a google apps script using src attribute. I put the folder id and the path. But the image couldn't display. I shared the folder here.

Thank you for your help!

https://drive.google.com/drive/folders/0ByNw-B9nXMcbMkxHTGt2X2xUTzQ

function doGet() {
  var html = HtmlService.createTemplateFromFile('index').evaluate()
    .setTitle('picture').setSandboxMode(HtmlService.SandboxMode.NATIVE);
  return html;
}

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
  <p> Dispaly picture </p>
    <p><img src="https://drive.google.com/drive/folders/0ByNw-B9nXMcbMkxHTGt2X2xUTzQ/200w.gif"> </p>
  </body>
</html>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The img src="" requires the URL of the actual image you want to display, not the folder that contains it. To get the correct link you need to open the picture in its own window or click share and get the link that way.

The correct link for your image is:

https://drive.google.com/file/d/0ByNw-B9nXMcbSTN2S2ZiYWprdzA/view

To use this in the src you need to add the fileID to the end of this format URL:

https://drive.google.com/uc?export=download&id=

So it becomes:

https://drive.google.com/uc?export=download&id=0ByNw-B9nXMcbSTN2S2ZiYWprdzA

NOTE: The drive file must be shared with 'anyone with the link' for other users to be able to view the file or for use outside of G Suite.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...