# Trying to save an .xlsx file attached to an email into a local directory

**URL:** https://discourse.nodered.org/t/trying-to-save-an-xlsx-file-attached-to-an-email-into-a-local-directory/17057
**Category:** General
**Created:** [23 October 2019 17:32 UTC](https://discourse.nodered.org/t/trying-to-save-an-xlsx-file-attached-to-an-email-into-a-local-directory/17057 "2019-10-23T17:32:21Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![gv\_gv](https://avatars.discourse-cdn.com/v4/letter/g/ecccb3/32.png) [@gv\_gv](https://discourse.nodered.org/u/gv_gv)
#### Post date: [23 October 2019 17:32 UTC](https://discourse.nodered.org/t/trying-to-save-an-xlsx-file-attached-to-an-email-into-a-local-directory/17057/1 "2019-10-23T17:32:21Z")

</div>

Hello Guys,

I am trying to fetch an email attachment which is a .xlsx file.  
I moved the arraybuffer of the attachment content to msg.payload and used file node to try to save it as test.xlsx.  
But the saved .xlsx file is currupt.  
And the strage part is it did work as i intended once so i am totaly lost what exactly is the problem.  
Ive mentioned the code for the flow below.

```auto
[{"id":"227f4b0e.7a7ac4","type":"inject","z":"ed20e334.d0265","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":917,"wires":[["a512ec0f.4c98a"]]},{"id":"a512ec0f.4c98a","type":"e-mail in","z":"ed20e334.d0265","name":"Office email","protocol":"IMAP","server":"outlook.office365.com","useSSL":true,"port":"993","box":"IOT","disposition":"Read","criteria":"FLAGGED","repeat":"300","fetch":"trigger","inputs":1,"x":110,"y":997,"wires":[["f4b39742.fb9b58"]]},{"id":"f0d976ef.784b68","type":"debug","z":"ed20e334.d0265","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":750,"y":997,"wires":[]},{"id":"f4b39742.fb9b58","type":"filter","z":"ed20e334.d0265","name":"mfg cost","property":"topic","propertyType":"msg","asArray":false,"itemProperty":"","itemPropertyType":"item","rules":[{"t":"cont","v":"Mfg cost for the month of ","vt":"str","output":1}],"checkall":"true","outputs":1,"x":260,"y":997,"wires":[["9eb64d36.1aa6d"]]},{"id":"9eb64d36.1aa6d","type":"change","z":"ed20e334.d0265","name":"move to payload","rules":[{"t":"move","p":"attachments[0].content","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":997,"wires":[["1bbd5c41.6018d4"]]},{"id":"1bbd5c41.6018d4","type":"file","z":"ed20e334.d0265","name":"test","filename":"E:\\greenshot\\email attachment test\\test.xlsx","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"utf8","x":610,"y":997,"wires":[["f0d976ef.784b68"]]}]

```

regards,  
Gourav

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/06e30534fb7aa9d5783ec516d2ee2399e33a9432.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/02470e2f99fd1bdaf9ffb291f816f1d1b58a3012.png)

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [23 October 2019 17:56 UTC](https://discourse.nodered.org/t/trying-to-save-an-xlsx-file-attached-to-an-email-into-a-local-directory/17057/2 "2019-10-23T17:56:03Z")

</div>

Well you probably shouldn't add a carriage return to the end of the file as that may corrupt it  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6c33351e581b2c84b0e52068d79f6b139715f2f1.png)  
Also utf8 format "may" be ok - but I would probably try binary as it won't try and be too clever with extended characters.

---

<div class="post-metadata">

### Author: ![gv\_gv](https://avatars.discourse-cdn.com/v4/letter/g/ecccb3/32.png) [@gv\_gv](https://discourse.nodered.org/u/gv_gv)
#### Post date: [24 October 2019 15:26 UTC](https://discourse.nodered.org/t/trying-to-save-an-xlsx-file-attached-to-an-email-into-a-local-directory/17057/3 "2019-10-24T15:26:36Z")

</div>

Hi, thanks for the reply. I just chnage encoding to default and it worked.

```auto
[{"id":"227f4b0e.7a7ac4","type":"inject","z":"ed20e334.d0265","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":917,"wires":[["a512ec0f.4c98a"]]},{"id":"a512ec0f.4c98a","type":"e-mail in","z":"ed20e334.d0265","name":"Office email","protocol":"IMAP","server":"outlook.office365.com","useSSL":true,"port":"993","box":"IOT","disposition":"Read","criteria":"FLAGGED","repeat":"300","fetch":"trigger","inputs":1,"x":110,"y":997,"wires":[["f4b39742.fb9b58"]]},{"id":"f0d976ef.784b68","type":"debug","z":"ed20e334.d0265","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":750,"y":997,"wires":[]},{"id":"f4b39742.fb9b58","type":"filter","z":"ed20e334.d0265","name":"mfg cost","property":"topic","propertyType":"msg","asArray":false,"itemProperty":"","itemPropertyType":"item","rules":[{"t":"cont","v":"Mfg cost for the month of ","vt":"str","output":1}],"checkall":"true","outputs":1,"x":260,"y":997,"wires":[["9eb64d36.1aa6d"]]},{"id":"9eb64d36.1aa6d","type":"change","z":"ed20e334.d0265","name":"move to payload","rules":[{"t":"move","p":"attachments[0].content","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":997,"wires":[["1bbd5c41.6018d4"]]},{"id":"1bbd5c41.6018d4","type":"file","z":"ed20e334.d0265","name":"test","filename":"E:\\greenshot\\email attachment test\\test.xlsx","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"none","x":610,"y":997,"wires":[["f0d976ef.784b68"]]}]

```

---

<div class="post-metadata">

### Author: ![E-J-D](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@E-J-D](https://discourse.nodered.org/u/E-J-D)
#### Post date: [2 May 2024 08:23 UTC](https://discourse.nodered.org/t/trying-to-save-an-xlsx-file-attached-to-an-email-into-a-local-directory/17057/4 "2024-05-02T08:23:43Z")

</div>

Hi @gv_gv, it seems that your solved problem is very similar to mine. Unfortunately I cannot use your provided flow as I get "unknown node type "filter"", when importing. It would be great if you can post an updated flow here or give me a hint how to solve. Thanks!

 ![Clipboard_05-02-2024_01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/c/8c2c7b6d5edc19944f8be93607b7b2533e97a935.png)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [2 May 2024 08:41 UTC](https://discourse.nodered.org/t/trying-to-save-an-xlsx-file-attached-to-an-email-into-a-local-directory/17057/5 "2024-05-02T08:41:18Z")

</div>

Hi @E-J-D welcome to the forum.

It is a contrib node (type not explained by the OP).

It sems to be checking the incoming message contains the thing(s) they are interested in.  
Likely a simple `switch` node or `function` node can replace this in your case. Or simply delete it and allow all emails to be processed.

Other than that, i will be closing this 5y old topic.

If my advise above doesn't help you, please open a new topic & link back to this if needed.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [2 May 2024 08:41 UTC](https://discourse.nodered.org/t/trying-to-save-an-xlsx-file-attached-to-an-email-into-a-local-directory/17057/6 "2024-05-02T08:41:23Z")

</div>


