I've been creating Drive files for a while now with Published Pages and Apps Script, but now has arrived a demand to create them from an external link, and I've created a Snippet to get base64 data from a POST and create a Drive file for it, it works great for <8kb data, anything greater than that throws me an GET
error which my limited knowledge can't debug.
The only limitation that's near this is the 8kb for headers size, but this ain't it, or I'm sending this as a header?
Here's the setup:
Published Code.gs:
function doPost( e ) {
var returnMsg;
try{
var splitBase = (e.parameter.base64).split(','),
type = splitBase[0].split(';')[0].replace('data:',''),
nomeArq = (new Date()).getTime();
var byteCharacters = Utilities.base64Decode(splitBase[1]);
var ss = Utilities.newBlob(byteCharacters, type);
ss.setName(nomeArq);
var file = DriveApp.createFile(ss);
returnMsg = file.getId();
}catch(e){
returnMsg = 'Erro: ' + e.toString();
}
return ContentService.createTextOutput( returnMsg );
}
Ajax call on an external website that works (<8kb data):
function sendPostData() {
params = 'base64=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAO9SURBVDhPfZJrbBRVFMfPvTM7u7O7s7tlS9tsA+4CXZVXoG5aQGNtSyI1Rqlp4wMFQTC2H3xgIBSIfvBDCUG+aLAxWkkgGhUSTVRESduUIthaTKnLpl2DqSLQsG133efMnXuvd9pG2oT4z+TOnJv/78zJOQdxzmG+yE+X9M9Pk/N9LDEBnCOPx1YVsTdtVhoeBYxnTQBZUpgHk/7B7L6DdOiKFdjtwooAEGNywVAMU1q8mLW//fvGSNfoxc9i3Ut8gTuw/u2ZzLZd1pfAEBKYQkFhnGD0h1e+GFC6A/IvAUe83AvZFJhGW23rLGz0nk8/3gROFWRZYE7CHYRHS5QTK1xfLXOOlMggA5gUiAmUiWrA1Dsa37FgdnM8+WAtz2ZBUeyUq4SfCdpb6rzXyzBgCWzekKdskbaw1O0vVjWXzSlhnCtkW5c3WHBmz/7Ch51Yc7sIH3PjlhqtqypQGVzbXB6p9y1dxl2+LEHZHBQM0A1gDGQMqhPWVSKm61OrIjz1j8akvmLY8eK9VQ89tt++es1AHPp/1eOjRiJB02lGDFEwF6QQY0jC3ku9iAwMpjY96cTyoIvs+uCFT3H12s5vcl1dhXyGKwrIkjUe0T6rg+IEUapIQIhedKgdm9GrCjFjGrz3fmvsdD781CsT577P2xD4vMipIkVBooWShMTYsJVDNehAJEg1NxsexjCVzDPz7Lb6YydiqS+/KPjcSFWF1SpvvsRUFJNdLnWkV4aLJtM0m8OyQx1ZXl53Gxxnu023c3rAd5fEOC4YH7XUPTI8bhAi6sIoFPT6/BU/DOiq8j8kZtybN3c0LHi+okbrH6JiXKF7sLSheunoLUil5u7tXIlqZcrdurm9zh068m59W0eOGsgmK7U1WNfc1yP3Oww645srK+TcRRgFtrnByw/sbj95dTIeFddSuEJevQr33LxSH771p9/hMTie3tWZR2AOk2uEx4rklU/7fG+89sntYOrwYe5yAaXq7leFBS9SfH/7ePXWwNdhV1GW+jPUn7POBTl6zStv3eip3OLa+fqhk9L6zM4W0ybzZFJparQ3NQrYWs+jg6fe/PEoOGVPCm+4ofvzbMKB+krljIeWBFZ89+yRB3pGppqbxX7xdMa+5Rmts0OQs7B49fw1dPDC8QvjMaCF6RYp9xWH9qx/bnvoYXTs44m9+8QdKvarL7/kPLB3hrQk4P90LXlDZDk3djmaGLPi3p/Tm55IaAsn16zLtL1ljsanXXc0++e7yKTmb1EQK1lSIpWVzl7OFcC/7h3OG6Ox3twAAAAASUVORK5CYII=';
params = params.replace(/\+/g,'%2b');
url = #ThePublishedUrl#/exec;
$.ajax({
crossDomain : true,
url : url,
type : 'post',
data : params,
dataType : 'jsonp',
contentType : 'jsonp',
processData : false,
success : function (data) {
alert(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("some error");
}
});
}