# Writing file to gateway

**URL:** <https://forum.inductiveautomation.com/t/writing-file-to-gateway/81724>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [November 9, 2023, 3:34pm UTC](https://forum.inductiveautomation.com/t/writing-file-to-gateway/81724 "2023-11-09T15:34:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siebold](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/siebold/32/47336_2.png) [@Siebold](https://forum.inductiveautomation.com/u/Siebold)\
**Post date:** [November 9, 2023, 3:34pm UTC](https://forum.inductiveautomation.com/t/writing-file-to-gateway/81724/1 "2023-11-09T15:34:44Z")

</div>

I am trying to save a file to the gateway with the following script,

```auto
filename = system.file.saveFile(str(time) + "_" + str(sn) + ".txt")
	if filename is not None:
		system.file.writeFile(filename,text)

```

but this gives the error

```auto

Error running action 'dom.onClick' on Straightening@D/root/checkButton: Traceback (most recent call last): File "<function:runAction>", line 13, in runAction File "<module:CheckPart>", line 78, in savePart AttributeError: 'com.inductiveautomation.ignition.common.script.Imm' object has no attribute 'saveFile' 

```

What should I be doing instead to save a file to the gateway via a script?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 9, 2023, 5:48pm UTC](https://forum.inductiveautomation.com/t/writing-file-to-gateway/81724/2 "2023-11-09T17:48:56Z")

</div>

You are trying to use a Vision function in Perspective. Vision has direct access to the filesystem at the client machine, and can therefore present a file/folder chooser and can write results directly to that filesystem.

Perspective runs all scripts in the gateway, and the Vision file chooser doesn't exist for it. If you really want to save in the gateway, you will need to already know what folder and filename to use.

If you want to save in the client, you need to use `system.perspective.download()` to prompt the user to save the file. You won't have any say in where the user puts it in their system, though you can (and should) suggest a file name.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 9, 2023, 5:55pm UTC](https://forum.inductiveautomation.com/t/writing-file-to-gateway/81724/3 "2023-11-09T17:55:19Z")

</div>

In other words - `system.file.writeFile` is the correct function to use _to write the file to the gateway_, but you need some other mechanism to get the 'path to save the file to', such as a simple text field or popup view or something else; `system.file.saveFile` is a poorly named, poorly-located Vision only function.

---

<div class="post-metadata">

**Author:** ![Siebold](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/siebold/32/47336_2.png) [@Siebold](https://forum.inductiveautomation.com/u/Siebold)\
**Post date:** [November 9, 2023, 6:29pm UTC](https://forum.inductiveautomation.com/t/writing-file-to-gateway/81724/4 "2023-11-09T18:29:36Z")

</div>

I see I just have to give it the correct path and it worked. The documentation that said this worked in Perspective was where I got the script example from so I figured everything in the script would work with Perspective.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 9, 2023, 6:55pm UTC](https://forum.inductiveautomation.com/t/writing-file-to-gateway/81724/5 "2023-11-09T18:55:00Z")

</div>

Can you link whatever documentation page you got that example from?

---

<div class="post-metadata">

**Author:** ![Siebold](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/siebold/32/47336_2.png) [@Siebold](https://forum.inductiveautomation.com/u/Siebold)\
**Post date:** [November 9, 2023, 6:56pm UTC](https://forum.inductiveautomation.com/t/writing-file-to-gateway/81724/6 "2023-11-09T18:56:27Z")

</div>

[https://docs.inductiveautomation.com/display/DOC81/system.file.writeFile](https://docs.inductiveautomation.com/display/DOC81/system.file.writeFile)

Scope has both vision and perspective in it which seems to be true for the topic of the page, writeFile, but I assumed it also meant the same for the whole snippet.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [November 9, 2023, 7:35pm UTC](https://forum.inductiveautomation.com/t/writing-file-to-gateway/81724/7 "2023-11-09T19:35:36Z")

</div>

Documentation already updated. This right here is why you guys are really the best around.
