List of usage examples for com.liferay.portal.kernel.repository LocalRepository addFileEntry
public FileEntry addFileEntry(long userId, long folderId, String sourceFileName, String mimeType, String title, String description, String changeLog, File file, ServiceContext serviceContext) throws PortalException;
From source file:com.liferay.portlet.documentlibrary.service.impl.DLAppLocalServiceImpl.java
License:Open Source License
/** * Adds a file entry and associated metadata based on a {@link File} object. * * <p>/*from ww w .j a v a2 s.co m*/ * This method takes two file names, the <code>sourceFileName</code> and the * <code>title</code>. The <code>sourceFileName</code> corresponds to the * name of the actual file being uploaded. The <code>title</code> * corresponds to a name the client wishes to assign this file after it has * been uploaded to the portal. If it is <code>null</code>, the <code> * sourceFileName</code> will be used. * </p> * * @param userId the primary key of the file entry's creator/owner * @param repositoryId the primary key of the repository * @param folderId the primary key of the file entry's parent folder * @param sourceFileName the original file's name * @param mimeType the file's MIME type * @param title the name to be assigned to the file (optionally <code>null * </code>) * @param description the file's description * @param changeLog the file's version change log * @param file the file's data (optionally <code>null</code>) * @param serviceContext the service context to be applied. Can set the * asset category IDs, asset tag names, and expando bridge * attributes for the file entry. In a Liferay repository, it may * include: <ul> <li> fileEntryTypeId - ID for a custom file entry * type </li> <li> fieldsMap - mapping for fields associated with a * custom file entry type </li> </ul> * @return the file entry * @throws PortalException if the parent folder could not be found or if the * file entry's information was invalid * @throws SystemException if a system exception occurred */ public FileEntry addFileEntry(long userId, long repositoryId, long folderId, String sourceFileName, String mimeType, String title, String description, String changeLog, File file, ServiceContext serviceContext) throws PortalException, SystemException { if (file == null || !file.exists() || (file.length() == 0)) { return addFileEntry(userId, repositoryId, folderId, sourceFileName, mimeType, title, description, changeLog, null, 0, serviceContext); } LocalRepository localRepository = getLocalRepository(repositoryId); FileEntry fileEntry = localRepository.addFileEntry(userId, folderId, sourceFileName, mimeType, title, description, changeLog, file, serviceContext); dlAppHelperLocalService.addFileEntry(userId, fileEntry, fileEntry.getFileVersion(), serviceContext); return fileEntry; }