Skip to content

Instantly share code, notes, and snippets.

@kimakunc
Created July 26, 2016 19:46
Show Gist options
  • Save kimakunc/b6e42f6c2d1054a3e48a0ac1873838a2 to your computer and use it in GitHub Desktop.
Save kimakunc/b6e42f6c2d1054a3e48a0ac1873838a2 to your computer and use it in GitHub Desktop.
Liferay 6.2 add multipart File to DL
private FileEntry addFileEntry(CommonsMultipartFile multipartFile, long userId, long repositoryId,
ServiceContext serviceContext, long folderId, String sourceFileName, String mimeType, String title,
String changeLog, String description) throws PortalException, SystemException {
FileEntry fileEntry = null;
try {
fileEntry = DLAppLocalServiceUtil.addFileEntry(userId, repositoryId, folderId, sourceFileName, mimeType,
title, description, changeLog, multipartFile.getBytes(), serviceContext);
} catch (DuplicateFileException dfe) {
String extention = FileUtil.getExtension(title);
String strippedTitle = FileUtil.stripExtension(title);
String newTitle = strippedTitle + StringPool.UNDERLINE + String.valueOf(new Date().getTime())
+ StringPool.PERIOD + extention;
fileEntry = addFileEntry(multipartFile, userId, repositoryId, serviceContext, folderId, sourceFileName,
mimeType, newTitle, changeLog, description);
}
return fileEntry;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment