论坛

主页 » Liferay Portal » English » 3. Development

组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
toggle
Madhuri Potdar
Error received while uploading file to Document Library folder
2012年4月2日 上午4:40
答复

Madhuri Potdar

等级: New Member

帖子: 1

加入日期: 2012年4月2日

最近的帖子

I have created a folder in document library and then trying to upload a .xls or .xlsx file to this folder programmaticaly. This is working fine when I am trying to run it on local server. However when I am running it in shared environment, it is somehow appending .null to the file name and giving following error -
Error occured while storing input file in Document Library folder
com.liferay.documentlibrary.FileExtensionException: upload_00000383.xlsx.null

Here is the code I am using for this -

ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
long realUserId = themeDisplay.getRealUserId();
long groupId = themeDisplay.getLayout().getGroupId();
ServiceContext serviceContext = new ServiceContext();
serviceContext.setScopeGroupId(groupId);

DLFolder folder = DLFolderLocalServiceUtil.addFolder(realUserId, groupId, 0, "TestFolderName","Test Folder Description", serviceContext);

UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(request);
File file = uploadPortletRequest.getFile("path");

DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.addFileEntry(realUserId,groupId,folder.getFolderId(), file.getName(), file.getName(), "", "", folderName, file, serviceContext);

Anyone having any idea why .null might be getting appended to file name during upload?
Andy Harb
RE: Error received while uploading file to Document Library folder
2012年4月25日 上午8:22
答复

Andy Harb

等级: Junior Member

帖子: 65

加入日期: 2009年10月22日

最近的帖子

Hi Madhuri,

Where you ever able to figure this out? I am experiencing the same problem and can't track it down.

Thanks
Andy
Nagendra Kumar Busam
RE: Error received while uploading file to Document Library folder
2012年4月25日 上午9:04
答复

Nagendra Kumar Busam

等级: Liferay Master

帖子: 637

加入日期: 2009年7月7日

最近的帖子

Hi Madhuri,

Can you explain a bit about shared environment you are referring to
- Nagendra Kumar
Andy Harb
RE: Error received while uploading file to Document Library folder
2012年4月25日 下午3:05
答复

Andy Harb

等级: Junior Member

帖子: 65

加入日期: 2009年10月22日

最近的帖子

Figured it out:

You need to define the extension and content type in the service context as attributes:

1
2  String contentType = uploadRequest.getContentType("file");
3  serviceContext.setAttribute("contentType", contentType);
4   String extension = com.liferay.portal.kernel.util.FileUtil.getExtension(file.getName());
5   serviceContext.setAttribute("extension", extension);
Hitoshi Ozawa
RE: Error received while uploading file to Document Library folder
2012年4月25日 下午3:03
答复

Hitoshi Ozawa

等级: Liferay Legend

帖子: 7952

加入日期: 2010年3月23日

最近的帖子

You need to define the extension and content type in the service builder as attributes:


Just so other reader won't get confused, you mean "service context".
Andy Harb
RE: Error received while uploading file to Document Library folder
2012年4月25日 下午3:05
答复

Andy Harb

等级: Junior Member

帖子: 65

加入日期: 2009年10月22日

最近的帖子

Thanks for the correction! Edited original post