# Save temporary upload files byte stream in memory

**URL:** <https://forum.inductiveautomation.com/t/save-temporary-upload-files-byte-stream-in-memory/86648>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [March 1, 2024, 5:11am UTC](https://forum.inductiveautomation.com/t/save-temporary-upload-files-byte-stream-in-memory/86648 "2024-03-01T05:11:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [March 1, 2024, 5:11am UTC](https://forum.inductiveautomation.com/t/save-temporary-upload-files-byte-stream-in-memory/86648/1 "2024-03-01T05:11:58Z")

</div>

Hi  
I want the users able to upload some files in UI and finally send an email. So to do this I need to temporarily save the uploaded files stream somewhere and then when the user clicks on the send button I use them in my script to use them as email attachments.  
I tried to use a custom property on view to save file bytes stream but this caused the designer to crash and also it converted the format.  
I also try maybe system.util.getGlobals() it works but for images, I see the same crashing behavior as the file size is big.(500Kb)  
So what is the best method to save user attachments?

---

<div class="post-metadata">

**Author:** ![schenk](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@schenk](https://forum.inductiveautomation.com/u/schenk)\
**Post date:** [March 1, 2024, 11:50am UTC](https://forum.inductiveautomation.com/t/save-temporary-upload-files-byte-stream-in-memory/86648/2 "2024-03-01T11:50:49Z")

</div>

You should be able to handle this by using a temporary file.

Create a file with something like this on the File Upload component

```auto
fileBytes = event.file.getBytes()
extension = event.file.name.split('.')[-1] 
tempFilePath = system.file.getTempFile(extension)
system.file.writeFile(tempFilePath, fileBytes)

# Store the temporary file path in a custom property
self.view.custom.tempFilePath = tempFilePath

```

When you want to send the email, you can read the file back like this:

```auto
tempFilePath = self.view.custom.tempFilePath
fileBytes = system.file.readFileAsBytes(tempFilePath)
...

```

The uploaded files will be deleted when the gateway restarts

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [March 1, 2024, 9:22pm UTC](https://forum.inductiveautomation.com/t/save-temporary-upload-files-byte-stream-in-memory/86648/3 "2024-03-01T21:22:53Z")

</div>

I think of that way but I think it is not efficient for the server to handling. So do you think the mail server like the Gmail service this method?  
Don't we have any global memory to use for this?
