![](/img/trans.png)
[英]Copy image from Google Sheets to Google Docs using Google Apps Script
[英]Adding an image to a Google site from Docs using Apps Script
我有一個腳本,該腳本允許用戶將圖像上載到Google Docs,但此部分有效,但是我需要一種方法來檢索圖像本身,以便可以在Google網站上顯示該圖像。 我嘗試使用doc.getUrl(),但這僅返回下載圖像的鏈接。 有誰知道如何做到這一點,或以其他方式來處理圖片上傳效果更好?
這是我的代碼:
function doGet(e) {
var app = UiApp.createApplication().setTitle("Upload");
var formContent = app.createVerticalPanel();
formContent.add(app.createFileUpload().setName('thefile'));
formContent.add(app.createSubmitButton('Submit'));
var form = app.createFormPanel();
form.add(formContent);
app.add(form);
return app;
}
function doPost(e) {
var fileBlob = e.parameter.thefile;
var doc = DocsList.createFile(fileBlob);
var url = doc.getUrl();
Logger.log(url);
}
在此先感謝您的幫助。
將文件上傳到Google雲端硬盤時,您沒有直接鏈接到文件(或圖片)的鏈接,因此無法將其嵌入任何位置。
解決方案是將圖像另存為Google Sites頁面的附件,然后在您的Google Sites頁面中使用該圖像。
在執行此操作時,還請注意第912期,因此您需要在公共站點上提供圖像
如果可以獲取文檔ID,則可以創建一個直接下載鏈接,如下所示:
https://docs.google.com/uc?export=download&id=doc_id_here
因此是一個圖像嵌入標簽:
<img src="https://docs.google.com/uc?export=download&id=doc_id_here" />
不確定下載性能,但是應該可以。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.