javascript - Create a new blob in memory using Apps Script - Stack Overflow

I want to create a new blob in memory, put the content in the blob, name it, and finally save it as a f

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.

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.

Share Improve this question edited Feb 7, 2015 at 19:59 Alan Wells 31.3k16 gold badges112 silver badges162 bronze badges asked Feb 7, 2015 at 4:57 Alejandro SilvestriAlejandro Silvestri 3,78434 silver badges46 bronze badges 2
  • 1 You can use the Utilities Service: Google Documentation - Utilities.newBlob() – Alan Wells Commented Feb 8, 2015 at 18:29
  • 1 Please see my updated answer. I had answered wrong initially. – Alan Wells Commented Feb 8, 2015 at 18:34
Add a ment  | 

1 Answer 1

Reset to default 5

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744295348a4567233.html

相关推荐

  • javascript - Create a new blob in memory using Apps Script - Stack Overflow

    I want to create a new blob in memory, put the content in the blob, name it, and finally save it as a f

    7天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信