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?
You should be able to handle this by using a temporary file.
Create a file with something like this on the File Upload component
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:
tempFilePath = self.view.custom.tempFilePath
fileBytes = system.file.readFileAsBytes(tempFilePath)
...
The uploaded files will be deleted when the gateway restarts
4 Likes
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?