Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
916 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...