Status Update
Comments
in...@gigasuperhyper.com <in...@gigasuperhyper.com> #2
Perhaps internally, getBlob()
always recreates the Blob without copying the name property from the original blob (which perhaps no longer exists). In that case, the name should be copied to the internal object on setBlob()
so it can be copied to the Blob object when getBlob()
is called.
lo...@google.com <lo...@google.com> #3
Hello,
This isn't reproducible on my side, can you provide an url where this is reproducible?
in...@gigasuperhyper.com <in...@gigasuperhyper.com> #4
The following script:
function foo() {
const doc = DocumentApp.openById("INSERTGOOGLEDOCSID");
const url = "https://drive.google.com/uc?id=1ZsRqX_9y9Iz322k3mtuS-qWyNRI9VHbI&export=download";
const body = doc.getBody();
const paragraph = body.appendParagraph("Sample paragraph");
const blob = UrlFetchApp.fetch(url).getBlob();
blob.setName("sampleName");
const image = paragraph.addPositionedImage(blob);
console.log("IMAGE BLOB HAS NAME " + image.getBlob().getName());
}
produces the following output:
12:35:43 PM Notice Execution started
12:35:45 PM Info IMAGE BLOB HAS NAME null
12:35:45 PM Notice Execution completed
I'd except the output to have "sampleName" as the blob name.
lo...@google.com <lo...@google.com> #5
Hello,
This can be achieved by adding the parameters export=view
and adding the right permission to the file.
For example:
function foo() {
const doc = DocumentApp.openById("INSERTGOOGLEDOCSID");
const url = "https://drive.google.com/uc?export=view&id=SOME_FILE_ID";
const body = doc.getBody();
const paragraph = body.appendParagraph("Sample paragraph");
const blob = UrlFetchApp.fetch(url).getBlob();
blob.setName("sampleName");
const image = paragraph.addPositionedImage(blob);
console.log("IMAGE BLOB HAS NAME " + image.getBlob().getName());
}
Closing this issue as working as expected, if you encounter a case where this is not true, please, reach me again.
in...@gigasuperhyper.com <in...@gigasuperhyper.com> #6
No, the example code doesn't work:
8:35:06 PM Notice Execution started
8:35:07 PM Info IMAGE BLOB HAS NAME null
8:35:07 PM Notice Execution completed
Does your output really give a non-null blob name?
Description
The name property of a Google Docs Blob isn't copied around appropriately when used in PositionedImages (haven't tried InlineImage)
Ie the following code returns null:
I would expect the code to return the same name back.