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: SyntaxError: Unexpected token ; {"host":"","request_uri":"/rest/files/applications/app/?check_exist=false","source_ip":"","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?


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.



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:
  • 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.

thank you very much - your solution worked perfectly…

Thanks again