Hey everyone.
Iโm working on a script that will intercept emails, copy some details into a Gsheet, and copy the attachment into the Gdrive (while also putting a filepath into a cell for the row created per email).
The problem Iโm having is that the actual file created isnโt a copy of the attachment file, itโs a 15kb PDF with the following contents:
Everything in here works, except for attachment.copyBlob()
- thatโs creating the small bit of text you see in the images above.
You can see from the script fragment above that the attachment stuff is inside a loop;
newFilePath
.But when I tried return newFilePath
, it validated but itโs not actually returning a value; the filepath thatโs reported is missing the file name.
The code is built for multiple attachments, but I really only need it for one. In this scenario, there will only always be one attachment - but I canโt find anything that shows how to code for a single thing, itโs all for multiple (which makes sense).
Thanks to you all!
I think you need to getMimeType() in your ForEach() loop and use that type for the new blob().
@GreenFlux I originally had that in there, pulling the PDF type from the attachment and setting that to the mime type - but it produced the same result. It was my thought that if I didnโt specify the mimeType it would figure it out itself.
Maybe this for Problem #2?
Indeed you were correct @Marc_Dillon thanks!
Still having a problem with actually copying the content of the pdf.
When I investigate whatโs inside the attachmentโฆ Iโm finding that itโs actually empty.
I have no idea what Iโm doing wrong. attachment.copyBlob() is the only thing that people are putting out there in the internet, thereโs no other methods or anything that I can find.
Yet in my case, it doesnโt actually pull the attachment.
I must be missing something.
I would try this solution Copying Gmail attachments to Google Drive using Apps Script - Stack Overflow
Thanks for the info, the problem Iโm facing wonโt be solved by the link youโve suggested.
attachment.copyBlob()
My problem is that itโs not copying the blob - itโs actually causing some sort of error within the PDF file itself, some kind of error or something.
Iโm pretty much abandoning this for now, as Iโve managed to extract the data from the attachment using attachment.getPlainBody()
- and thatโs good enough for now.
But sure would be nice, and my client is expecting, the file from the gmails to be entered into the Gdrive.
User | Count |
---|---|
41 | |
36 | |
28 | |
23 | |
16 |