如何在 liferay 6.1
中将文件上传到文档和库我正在使用
addFileEntry(long userId, long groupId, long repositoryId, long folderId, String sourceFileName, String mimeType, String title, String description, String changeLog, long fileEntryTypeId, Map<String,Fields> fieldsMap, File file, InputStream is, long size, ServiceContext serviceContext)
DLFileEntryLocalServiceUtil
类的
答案 0 :(得分:0)
public void fileUpload(String filename)抛出异常{
// file
File file = new File(filename);
if (file.exists()) {
long folderId = 12344;
long repositoryId = 10180;
// filename
String sourceFileName = file.getName();
// mimetype
String mimeType = "";
if (sourceFileName.substring(sourceFileName.length() - 4)
.compareToIgnoreCase(".pdf") == 0) {
mimeType = "application/pdf";
} else {
if (sourceFileName.substring(sourceFileName.length() - 4)
.compareToIgnoreCase(".xls") == 0) {
mimeType = "application/xls";
}
}
// for title
String title = file.getName();
// for description
String description = file.getName();
// changeLog
String changeLog = "";
// fileEntryTypeId
long fileEntryTypeId = 0;
// for fieldMap
Fields feild = null;
Map<java.lang.String, com.liferay.portlet.dynamicdatamapping.storage.Fields> fieldsMap = new HashMap<java.lang.String, com.liferay.portlet.dynamicdatamapping.storage.Fields>();
fieldsMap.put("", feild);
// for InputStream
InputStream is = new FileInputStream(file);
// for file size
double bytes = file.length();
long size = (long) (bytes / 1024);
// service Context Object
String uuid = UUID.randomUUID().toString();
Date date = new Date();
ServiceContext serviceContext = new ServiceContext();
serviceContext.setUuid(uuid);
serviceContext.setCreateDate(date);
serviceContext.setModifiedDate(date);
// PermissionChecking
PrincipalThreadLocal.setName(10196);
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil
.create(UserLocalServiceUtil.getUser(10196));
PermissionThreadLocal.setPermissionChecker(permissionChecker);
DLAppServiceUtil.addFileEntry(repositoryId, folderId,
sourceFileName, mimeType, title, description, changeLog,
is, size, serviceContext);
/*
* DLFileEntryLocalServiceUtil.addFileEntry(userId, groupId,
* repositoryId, folderId, sourceFileName, mimeType, title,
* description, changeLog, fileEntryTypeId, fieldsMap, file, is,
* size, serviceContext);
*/
}
}