robertoDiaz/liferay-portal — pull request #164 by giros (2014-12-15 15:46:52+00:00)
Title: [TECH SUPPORT] LPS-52005 Let the mimeType of wiki attachment be determined differently

Hi @robertoDiaz,

So to describe what is happening here:

MimeTypesImpl.getContentType(InputStream, String) modifies the InputStream that is passed to it, as a side effect. (It is done by the Apache Tika library.) Because of this, when creating a file from the same InputStream after this call, it results in an empty file. We should avoid calling directly MimeTypesUtil.getContentType(InputStream, String) in case we want to use that InputStream object afterwards.

Earlier the issue was avoided in WikiPageStagedModelDataHandler by closing the InputStream after this call and re-creating it by reading the binary from the LAR again. (See https://github.com/liferay/liferay-portal/commit/0c7eb127ae32aee15bd858caee9d8b4402feb248). This was later eliminated, because I guess it just didn't make any sense to Dani (https://github.com/liferay/liferay-portal/commit/7135bc2e865670421ae4d048c52c19b513bef4cd), and that change made this issue appear.

Instead of re-adding the redundant creation of the InputStream, we can just avoid using the above method directly, and let the mime type be determined later by PortletFileRepositoryImpl.addPortletFileEntry.

Let me know if you have any questions.

Regards,
G