Monday, June 3, 2024
32
rated 0 times [  38] [ 6]  / answers: 1 / hits: 7784  / 10 Years ago, sat, february 7, 2015, 12:00:00

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.


More From » google-apps-script

 Answers
1

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.


[#39426] Friday, February 6, 2015, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daquanmilesw

Total Points: 57
Total Questions: 102
Total Answers: 110

Location: Wallis and Futuna
Member since Sat, Aug 6, 2022
2 Years ago
;