Reputation: 21
In google app scripts, the following line throws error:
DriveApp.createFile( e.parameter.fileupBlob);
Where fileupBlob
is hidden field in the form with a BLOB stored in it.
Error thrown when executed:
Cannot find method createFile((class)). (line 23, file "Code", project "saving")
Upvotes: 1
Views: 2201
Reputation: 21
Got it! The javascript library was returning string dataURI and i replaced the first part of dataURI in jquery:
strDataURI=strDataURI.replace("data:image/png;base64,", "");
document.getElementById("blobobj").value = strDataURI;
Then i was able to create the image
var str=Utilities.base64Decode(e.blobobj);
var fileBlob = Utilities.newBlob(str).setContentType('image/png');
Upvotes: 1
Reputation: 590
Do this
let imageBlob = images[0].getBlob();
let name = 'fileName.jpeg';
let contentType = 'image/jpeg';
let fileBlob = Utilities.newBlob(imageBlob.getBytes(), contentType, name);
let imageFile = folder.createFile(fileBlob).setName('ravgeet.jpeg');
Upvotes: 1
Reputation: 5782
You need to create the blob as shown below. It is assuming you passed a valid blob. EDIT: If drive is having difficulty figuring out what type of file it is from the blob you can provide that info yourself. Another thought is that the blob may be base64 encoded. You may have to decode it before creating the new blob. You haven't posted any code so I can't tell what is going on.
var name = "fileName.png";
var contentType = "image/png";
var fileBlob = Utilities.newBlob(e.parameter.fileupBlob, contentType, name);
DriveApp.createFile(fileBlob);
Upvotes: 2
Reputation: 46802
The argument of DriveApp.createFile
must be a blob.
The value returned by e.parameter.varName
is a string.
Therefore the error you get. The only case when a blob is returned from a form is when you use a file upload widget, the hidden widget behaves like a text widget.
Upvotes: 2