Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: REST API upload requests are processed incorrectly when chunked
In HTTP 1.1 a special "Transfer-Encoding: chunked" header enables splitting the request to smaller parts.
When this mode is enabled, Multipart requests used for uploading data via REST API are handled incorrectly.
- Create a new KB Article
- In IDEA, add Vulcan Impl dependency to any custom module to be
able to set a breakpoint, see next step
implementation 'com.liferay:com.liferay.portal.vulcan.impl:5.0.68'
- In IDEA set a breakpoint inside readFrom() method of the MultipartBodyMessageBodyReader class
- Add KB article attachment using REST API with and without checked
encoding:
(for demonstration purposes just key=value form params are passed):
curl -X POST "http://localhost:8080/o/headless-delivery/v1.0/knowledge-base-articles/84163002/knowledge-base-attachments" -H "Content-Type: multipart/form-data" -F "key=value" -u "test@liferay.com:test"
curl -X POST "http://localhost:8080/o/headless-delivery/v1.0/knowledge-base-articles/84163002/knowledge-base-attachments" -H "Content-Type: multipart/form-data" -F "key=value" -H "Transfer-Encoding: chunked" -u "test@liferay.com:test"
- When the breakpoint is hit, inspect the fileItems list returned by
this line:
List<FileItem> fileItems = servletFileUpload.parseRequest( _httpServletRequest);
When chunked encoding is used, the list is empty. It means any passed params are discarded.
In some clients, like standard Java 11 HttpClient, it is not possible to disable that chunked encoding, so this client cannot be used for REST API calls at the moment.
Bug Report Created: https://liferay.atlassian.net/browse/LPS-203472
Hi Jan, this has been fixed and I can confirm it is in 112 which is currently planned to be the basis for the 2024 Q1 release.
Powered by Liferay™