Details
-
Bug
-
Status: Closed
-
Resolution: Fixed
-
7.0.0 DXP FP7, 7.0.0 DXP SP1, 7.0.0 DXP SP2, 7.0.X, 7.1.X, Master
-
None
Description
Description
While uploading multiple files to Liferay through JSONWS, it didn't upload multiple files properly and I got errors as follows:
> jodd.json.JsonException: Syntax error! Invalid char: C_offset: 1 near: "[C:\bin\lif..." [Sanitized] > at jodd.json.JsonParser.syntaxError(JsonParser.java:951) ... > at com.liferay.portal.json.JSONDeserializerImpl.deserialize(JSONDeserializerImpl.java:34) ... > at com.liferay.portal.jsonwebservice.JSONWebServiceActionImpl._convertValueToParameterValue(JSONWebServiceActionImpl.java:178) > at com.liferay.portal.jsonwebservice.JSONWebServiceActionImpl._prepareParameters(JSONWebServiceActionImpl.java:450)
Looking at the code,
/Users/yasuflatland/project/liferay-portal-ee/portal-impl/src/com/liferay/portal/jsonwebservice/JSONWebServiceActionParameters.java
in JSONWebServiceActionParameters#_collectFromRequestParameters(HttpServletRequest) method, the value is treated as File. But the value is supposed to be File array (File[]).
UploadServletRequest receives multiple files properly but this method
_jsonWebServiceActionParameters.put(parameterName, value)
put file data into HashMap<String, Object> with same key so I ended up getting the last file data of multiple files uploaded. This part should be fixed to be able to handle multiple files properly.
Steps to Reproduce
- 1. Deploy a service that will permit file upload through JSON WS
- Attached please find test.zip to unzip inside modules/apps dir of portal repository, run gradlew deploy
- Attached please find a copy of exampleFile.zip that you can run a "blade deploy" from the sample workspace.
- 2. Sign in to Liferay using [email protected] credentials
- 3. Go to the JSON WS method for the service created in step 1
(example: http://localhost:8080/api/jsonws?contextName=foo&signature=%2Ffoo.foo%2Faccept-1-files) - 4. At the bottom of the page, click Invoke.
- 5. Create two files called dummy.png and dummy1.png
- 6. Go to the path with the two files in Terminal
- 7. Run curl 'http://localhost:8080/api/jsonws/foo.foo/accept ' -u '[email protected]:test' -F [email protected] -F [email protected]
Expected Result
File is uploaded
Actual Result
a. An exception is thrown on the console running curl
{"exception":"Syntax error! Invalid char: /\noffset: 1 near: \"[/Users/lif...\"","throwable":"jodd.json.JsonException: Syntax error! Invalid char: /\noffset: 1 near: \"[/Users/lif...\"","error":{"message":"Syntax error! Invalid char: /\noffset: 1 near: \"[/Users/lif...\
b. An error is produced on Liferay's console
01:34:42,397 ERROR [http-nio-8080-exec-7][JSONWebServiceServiceAction:121] Syntax error! Invalid char: /_offset: 1 near: "[/Users/lif..." [Sanitized]