# Server-side script error when uploading files

**URL:** <https://community.dreamfactory.com/t/server-side-script-error-when-uploading-files/1395>\
**Category:** Server-Side Scripting\
**Created:** [August 19, 2015, 3:55pm UTC](https://community.dreamfactory.com/t/server-side-script-error-when-uploading-files/1395 "2015-08-19T15:55:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brunelamc](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@Brunelamc](https://community.dreamfactory.com/u/Brunelamc)\
**Post date:** [August 19, 2015, 3:55pm UTC](https://community.dreamfactory.com/t/server-side-script-error-when-uploading-files/1395/1 "2015-08-19T15:55:02Z")

</div>

I get the error below when I add either a post.pre\_process or a post.post\_process script to the file api.  
Here is the error from the web.\*.log file:

```
[ERROR] REST Exception #500 > Exception executing javascript: files.applications.post.pre_process.js:63: SyntaxError: Unexpected token ; {"host":"192.168.0.14:8080","request_uri":"/rest/files/applications/app/?check_exist=false","source_ip":"192.168.0.11","sapi_name":"apache2handler"}

```

Some background:  
I am trying to upload files via the files api using the android sdk. Without the scripts, file uploads of any kind are successful. However, pictures(.jpg and png) files result in the above error when either script type is enabled.

After doing some troubleshooting, I realized that the contents of the scripts did not matter. Having even empty scripts caused .picture uploads to fail with the same exact error above.

Any solutions/workarounds?

Thanks!

---

<div class="post-metadata">

**Author:** ![naveed10anjum](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@naveed10anjum](https://community.dreamfactory.com/u/naveed10anjum)\
**Post date:** [October 22, 2015, 10:36pm UTC](https://community.dreamfactory.com/t/server-side-script-error-when-uploading-files/1395/2 "2015-10-22T22:36:04Z")

</div>

Hi, did you figure out how to solve this issue. My post and pre process are not working at all. And i am getting the same error that you have. Any help will be greatly appreciated.

Thanks!

---

<div class="post-metadata">

**Author:** ![Brunelamc](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@Brunelamc](https://community.dreamfactory.com/u/Brunelamc)\
**Post date:** [October 23, 2015, 3:03am UTC](https://community.dreamfactory.com/t/server-side-script-error-when-uploading-files/1395/3 "2015-10-23T03:03:01Z")

</div>

Hi!

I did solve the issue. If I recall correctly, the issue was with the Json encoding when the script is being run. Here’s the fix:

- Edit the following file that runs the script engine, where platform is the location of the DSP:  
{platform}/dreamfactory-1.9.2-1/apps/dreamfactory/htdocs/vendor/dreamfactory/lib-php-common-platform/src/Scripting/ScriptEngine.php
- Replace the following line:  
$\_jsonEvent = json\_encode( exposedEvent, JSON\_UNESCAPED\_SLASHES); (Line 486) with the following line: \_jsonEvent = json\_encode( $exposedEvent, JSON\_UNESCAPED\_SLASHES | JSON\_PARTIAL\_OUTPUT\_ON\_ERROR );

The initial exception is thrown because the image cannot be decoded as a json, and the function “json\_encode()” exits with an error. The “JSON\_PARTIAL\_OUTPUT\_ON\_ERROR” flag solves the problem by ignoring the errors,and saving the decodeable part.

When I tested this, everything worked fine, and all my other parameters and headers were correctly decoded and preserved.

This should work for you too. Please post any updates/questions here.  
Best!

---

<div class="post-metadata">

**Author:** ![Naveed\_Anjum](https://avatars.discourse-cdn.com/v4/letter/n/13edae/32.png) [@Naveed\_Anjum](https://community.dreamfactory.com/u/Naveed_Anjum)\
**Post date:** [October 26, 2015, 7:43pm UTC](https://community.dreamfactory.com/t/server-side-script-error-when-uploading-files/1395/4 "2015-10-26T19:43:16Z")

</div>

thank you very much - your solution worked perfectly…

Thanks again
