Skip to content

Instantly share code, notes, and snippets.

@marcosblandim
Created September 14, 2023 03:13
Show Gist options
  • Save marcosblandim/d823780fc99b05a620af936dc8de3c0d to your computer and use it in GitHub Desktop.
Save marcosblandim/d823780fc99b05a620af936dc8de3c0d to your computer and use it in GitHub Desktop.
Create DL File from text in Liferay Groovy
import com.liferay.document.library.kernel.service.DLAppLocalServiceUtil
import com.liferay.petra.string.StringPool
import com.liferay.portal.kernel.service.ServiceContextThreadLocal
import java.nio.charset.StandardCharsets
void createDLFile(String filnameWithExtension, long folderId, String mimeType, String title, String description, String text) {
def serviceContext = ServiceContextThreadLocal.getServiceContext()
def inputStream = new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8))
DLAppLocalServiceUtil.addFileEntry(
serviceContext.getUserId(), serviceContext.getScopeGroupId(), folderId,
filnameWithExtension, mimeType, title,
description, StringPool.BLANK, inputStream,
0, serviceContext)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment