使用Google Apps脚本Blob转换数据URI [英] Convert Data URI using Google Apps Script Blob

查看:88
本文介绍了使用Google Apps脚本Blob转换数据URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Google Apps脚本中的数据URI上传并保存图像.一切都与设置的文件类型不同.

I am trying to upload and save an image from Data URI in Google Apps Script. Everything works apart from the file type being set.

我已经按照Apps脚本文档尝试过newBlob的所有变体.

I've tried all variations of newBlob as per the Apps Script documentation.

function doUpload(dataURI) {

var folder = DriveApp.getFolderById("xxxxxxxxxxxxxxxxxxxxxx");
var type = (dataURI.split(";")[0]).replace('data:','');
var imageUpload = Utilities.base64Decode(dataURI.split(",")[1]);
var blob = Utilities.newBlob(imageUpload, type, "nameOfImage");
folder.createFile(blob);

return true;
}

推荐答案

这是小而重要的修改...

Here is the small and important modification...

function doUpload(dataURI) {

var folder = DriveApp.getFolderById("xxxxxxxxxxxxxxxxxxxxxx");
var type = (dataURI.split(";")[0]).replace('data:','');
var imageUpload = Utilities.base64Decode(dataURI.split(",")[1]);
var blob = Utilities.newBlob(imageUpload, type, "nameOfImage.png");
folder.createFile(blob);

return true;
}

这篇关于使用Google Apps脚本Blob转换数据URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆