Reputation: 3774
I want to create a new blob in memory, put the content in the blob, name it, and finally save it as a file in Drive.
I know how to create a file in Drive from blobs. The only thing I'm looking for is creating the empty new blob to start with.
Upvotes: 3
Views: 9376
Reputation: 31300
You can create a new blob in memory with the Utilities Service:
function createNewBlob() {
var blobNew = Utilities.newBlob("initial data");
blobNew.setName("BlobTest");
Logger.log(blobNew.getName());
blobNew.setDataFromString("Some new Content");
Logger.log(blobNew.getDataAsString())
var newFileReference = DriveApp.createFile(blobNew);
newFileReference.setName('New Blob Test');
};
You can also create a new file, with some small amount of data, then change the content. In this example, a file is created in the root directory with the contents "abc". Then the content of the blob is set to something else.
function createNewBlob() {
// Create an BLOB file with the content "abc"
var blobNew = DriveApp.createFile('BlobTest', 'abc', MimeType.Blob);
Logger.log(blobNew.getName());
blobNew.setContent("Some new Content");
Logger.log(blobNew.getBlob().getDataAsString())
};
You could create data in memory, then create the blob with the finished data.
Upvotes: 5