# Perspective Gateway Message Handler with File Upload Component

**URL:** <https://forum.inductiveautomation.com/t/perspective-gateway-message-handler-with-file-upload-component/74961>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [June 13, 2023, 2:51pm UTC](https://forum.inductiveautomation.com/t/perspective-gateway-message-handler-with-file-upload-component/74961 "2023-06-13T14:51:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![David.Reed.Schmidt](https://avatars.discourse-cdn.com/v4/letter/d/5f9b8f/32.png) [@David.Reed.Schmidt](https://forum.inductiveautomation.com/u/David.Reed.Schmidt)\
**Post date:** [June 13, 2023, 2:51pm UTC](https://forum.inductiveautomation.com/t/perspective-gateway-message-handler-with-file-upload-component/74961/1 "2023-06-13T14:51:52Z")

</div>

I'm attempting to message file data from a perspective client to the gateway for further processing. I'm using the file upload component and the file is a CSV file. I'm logging the perspective session as well as on the gateway message side. The perspective session logs but the gateway for the message handler never logs which tells me that the message handler is never evoked.

The perspective side

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/2/b22cb0fd1895f7c35b1b1975606393b106b000fa.png)

The gateway side

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/c/bc1e4b679433b157f7dd319b44f21de79ad06f7c.png)

And on my gateway log  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/e/3ebe5b00d30d86b1789fa46d039a0656fdf6d453.png)

And this is the extend of what I get with the attempt. Am I missing something for getting the gateway handler to work with perspective. Once I get this working then I can complete the reset of the code.

---

<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:** [June 13, 2023, 2:56pm UTC](https://forum.inductiveautomation.com/t/perspective-gateway-message-handler-with-file-upload-component/74961/2 "2023-06-13T14:56:08Z")

</div>

You are trying to use the syntax and options for `system.util.sendMessage()` with `system.perspective.sendMessage()`. The latter only works within a Perspective session to send messages within the session/page/view.

I presume you are trying to send to a different gateway? (Because the file upload event runs in the gateway the Perspective client is running from, and can therefore do anything a message handler can do in that gateway.)

{Consider using `system.util.sendRequest()` so that you can return success/failure/whatever to indicate to the client.}

---

<div class="post-metadata">

**Author:** ![David.Reed.Schmidt](https://avatars.discourse-cdn.com/v4/letter/d/5f9b8f/32.png) [@David.Reed.Schmidt](https://forum.inductiveautomation.com/u/David.Reed.Schmidt)\
**Post date:** [June 13, 2023, 3:34pm UTC](https://forum.inductiveautomation.com/t/perspective-gateway-message-handler-with-file-upload-component/74961/3 "2023-06-13T15:34:22Z")

</div>

Changed my code to this

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/e/8edc90854d814afcc4e1aa5dfa9082c9eb053a2c.png)

And now my gateway log does this

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/7/87b8fca2a5a0a03c8fa38cd787b3afa94a99ac0e.png)

From what I can conclude is that the Gateway message handler will listen to calls from system.util.sendMessage called from a perspective session. I was not expecting this.

---

<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:** [June 13, 2023, 4:08pm UTC](https://forum.inductiveautomation.com/t/perspective-gateway-message-handler-with-file-upload-component/74961/4 "2023-06-13T16:08:38Z")

</div>

You aren't sending to a different gateway. Why are you bothering to use a message handler?

---

<div class="post-metadata">

**Author:** ![David.Reed.Schmidt](https://avatars.discourse-cdn.com/v4/letter/d/5f9b8f/32.png) [@David.Reed.Schmidt](https://forum.inductiveautomation.com/u/David.Reed.Schmidt)\
**Post date:** [June 13, 2023, 4:34pm UTC](https://forum.inductiveautomation.com/t/perspective-gateway-message-handler-with-file-upload-component/74961/5 "2023-06-13T16:34:14Z")

</div>

Honestly. Perspective back to the gateway to run a dataset at the gateway. Why not!

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 13, 2023, 4:42pm UTC](https://forum.inductiveautomation.com/t/perspective-gateway-message-handler-with-file-upload-component/74961/6 "2023-06-13T16:42:28Z")

</div>

> [@David.Reed.Schmidt](#):
>
> Why not!

Because perspective is already running on the gateway.

---

<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:** [June 13, 2023, 6:47pm UTC](https://forum.inductiveautomation.com/t/perspective-gateway-message-handler-with-file-upload-component/74961/7 "2023-06-13T18:47:07Z")

</div>

> [@pturmel](#):
>
> Because the file upload event runs in the gateway the Perspective client is running from, and can therefore do anything a message handler can do in that gateway.

This is the important bit.  
All scripts and bindings in "Perspective" are actually executing on the gateway already, because web browsers can't \[1\] run Python directly. So we've _already_ sent the file data to the backend during the file upload operation by the time your script is invoked. There's _no need_ to wrap it up and send it anywhere via a message handler, and in fact it's a hugely expensive operation that should be _avoided_ as much as possible. You should kick off (possibly async) a project library script to handle your uploaded file data _direct from the upload handler_.

* * *

1. Don't test me, pedants
