Решение
После дополнительного изучения вашего вопроса я обнаружил, что могу использовать объект Blob, который вы получаете из образа формы, для создания файла накопителя, который затем можно использовать для получения webContentLink
. URL-адрес для использования в веб-приложении с использованием Drive API .
Чтобы использовать API-интерфейс Drive в своем скрипте Apps Scrip, пожалуйста, в редакторе сценариев go - Ресурсы -> Advanced Cloud Services и включите Drive API в диалоговом окне, которое появится
Это фрагмент кода, который я использовал для достижения того, к чему вы стремились, с помощью поясняющих комментариев (это упрощенное веб-приложение, которое фокусируется только на достижении вашей цели):
Файл Code.gs
// Apps SCript function to serve the HTML file in the web
function doGet() {
return HtmlService.createHtmlOutputFromFile('test');
}
// Function to be called in the HTML that returns the URL to be used by the image tag
function getUrl() {
var form = FormApp.getActiveForm();
// Get image blob
var image = form.getItems()[0].asImageItem().getImage().getAs('image/jpeg');
// Use the image blob for creating a new drive file
var file = DriveApp.createFile(image);
// Use the Drive API get method to get the property webContentLink which will return the link
// of the image to be used in a website
var fileURL = Drive.Files.get(file.getId()).webContentLink;
return fileURL;
}
index. html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body id="body">
<h1>MY IMAGE</h1>
<script>
// Get what our function getURL returns
google.script.run.withSuccessHandler(function(URL) {
// Create HTML image tag
var img = document.createElement('img');
// Set its source to our file's sharable URL
img.src = URL;
// Attach image element to the body
document.getElementById('body').appendChild(img);
}).getURL();
</script>
</body>
</html>
Надеюсь, это помогло вам. Дайте мне знать, если вам нужно что-то еще или вы что-то не поняли. :)