Last active
January 4, 2016 18:59
-
-
Save yuya/8664592 to your computer and use it in GitHub Desktop.
Google Apps Script で簡易 Base64Encoder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getImageBase64(source) { | |
| var image = UrlFetchApp.fetch(source), | |
| blob, contentType, base64; | |
| if (!image) { | |
| return; | |
| } | |
| blob = image.getBlob(); | |
| contentType = blob.getContentType(); | |
| base64 = Utilities.base64Encode(blob.getBytes()); | |
| return "data:" + contentType + ";base64," + base64; | |
| } | |
| function doGet(req) { | |
| if (!req) { | |
| return; | |
| } | |
| var source = req.parameters.src, | |
| callback = req.parameters.callback ? req.parameters.callback : "callback", | |
| response = getImageBase64(source), | |
| mimeType = "JSON"; | |
| return ContentService.createTextOutput(callback + "(" + JSON.stringify({ data : response }) + ")") | |
| .setMimeType(ContentService.MimeType[mimeType]); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使うときは下記のように JSONP で base64 の文字列を受け取る