Googleドライブ内の画像ファイル
https://drive.google.com/file/d/ID/view?usp=sharing
を
data:image/png;base64, ここにbase64変換した文字列
の形にして返したい
コード.gs
function getBase64Data() {
var url = "https://drive.google.com/file/d/ID/view?usp=sharing";
var id = url.split("/d/")[1].split("/")[0];
var file = DriveApp.getFileById(id);
var blob = file.getBlob();
var content_type = blob.getContentType();
var base64 = Utilities.base64Encode(blob.getBytes());
var data = "data:" + content_type + ";base64, " + base64;
return data;
}
|
参考
base64Encode(data)
https://developers.google.com/apps-script/reference/utilities/utilities#base64Encode(Byte)