Apps Script公式リファレンス: Apps Script Reference |障害・課題追跡: IssueTracker |Google Workspace: Status Dashboard - Summary

2019年1月27日日曜日

Googleドライブ内の画像ファイルをbase64にencodeしたい


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)

Latest post

Google Apps Scriptの障害時はIssueTrackerを見てみる - Incidents for Apps Script are reported on Issue Tracker

IssueTracker > Apps Script issues https://issuetracker.google.com/savedsearches/566234 Google Apps Scriptの障害時は IssueTracker に課題が上がっていることが...