留言板

Error received while uploading file to Document Library folder

Madhuri Potdar,修改在12 年前。

Error received while uploading file to Document Library folder

New Member 发布: 1 加入日期: 12-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,修改在11 年前。

RE: Error received while uploading file to Document Library folder

Junior Member 帖子: 66 加入日期: 09-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
thumbnail
Nagendra Kumar Busam,修改在11 年前。

RE: Error received while uploading file to Document Library folder

Liferay Master 帖子: 678 加入日期: 09-7-7 最近的帖子
Hi Madhuri,

Can you explain a bit about shared environment you are referring to
- Nagendra Kumar
Andy Harb,修改在11 年前。

RE: Error received while uploading file to Document Library folder

Junior Member 帖子: 66 加入日期: 09-10-22 最近的帖子
Figured it out:

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


  String contentType = uploadRequest.getContentType("file");
  serviceContext.setAttribute("contentType", contentType);
   String extension = com.liferay.portal.kernel.util.FileUtil.getExtension(file.getName());
   serviceContext.setAttribute("extension", extension);
thumbnail
Hitoshi Ozawa,修改在11 年前。

RE: Error received while uploading file to Document Library folder

Liferay Legend 帖子: 7942 加入日期: 10-3-24 最近的帖子
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,修改在11 年前。

RE: Error received while uploading file to Document Library folder

Junior Member 帖子: 66 加入日期: 09-10-22 最近的帖子
Thanks for the correction! Edited original post