What is the substitute for hosting images in googl

2019-05-21 14:28发布

问题:

It was very simple before, simply using the URL https://googledrive.com/host/{file_Id} but, the problem arises because the web page hosting is being discontinued by Google?

You can check the Google Policy in the link here.

回答1:

First, we need to get the byte form of image stored in the drive, to do that use Utilities class of app script and encode that in base64 format

var base64_Encoded_Image= Utilities.base64Encode(DriveApp.getFileById('<image id in drive>').getBlob().getBytes());

now to add this image in <img> tag use this

<img alt='NA' src='data:image/png;base64,"+base64_Encoded_Image+"'/>


回答2:

Short answer

You could still use Google Drive to host images, by using the following URL pattern:

https://drive.google.com/uc?export=view&id={fileId} 

Explanation

I think that the above pattern was "discovered" by several user by inspecting the download button from the Google Drive preview page or another similar page. There are several posts around the web about this "trick", but it's not included in the official documentation so it could stop at any time without any previous announcement by Google.

Anyway, this could could serve well for some purposes.

References

Displaying files (e.g. images) stored in Google Drive on a website



回答3:

you may host the image as a google site resource (in a file cabinet or page attachment for example) which is free.

alternatively, you may host the image in a google cloud storage bucket (but that requires to enable project billing) and firebase also has a similar service.