Server-side script error when uploading files

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!

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!

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!

thank you very much - your solution worked perfectly…

Thanks again