If you need to create a new blob in memory, the Utilities Service provides a convenient solution:
function generateNewBlob() {
var newlyCreatedBlob = Utilities.newBlob("initial data");
newlyCreatedBlob.setName("BlobTest");
Logger.log(newlyCreatedBlob.getName());
newlyCreatedBlob.setDataFromString("Some fresh content");
Logger.log(newlyCreatedBlob.getDataAsString())
var newFileRef = DriveApp.createFile(newlyCreatedBlob);
newFileRef.setName('New Blob Test');
};
Alternatively, you can first create a new file with minimal data and then update its contents. For instance:
function generateUpdatedBlob() {
// Create a BLOB file with the initial content "abc"
var updatedBlob = DriveApp.createFile('BlobTest', 'abc', MimeType.Blob);
Logger.log(updatedBlob.getName());
updatedBlob.setContent("Some new Content");
Logger.log(updatedBlob.getBlob().getDataAsString())
};
You have the flexibility to manipulate data in memory before generating the final blob.