Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Madhuri Potdar
Error received while uploading file to Document Library folder
April 2, 2012 4:40 AM
Answer

Madhuri Potdar

Rank: New Member

Posts: 1

Join Date: April 2, 2012

Recent Posts

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
April 25, 2012 8:22 AM
Answer

Andy Harb

Rank: Junior Member

Posts: 64

Join Date: October 22, 2009

Recent Posts

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
April 25, 2012 9:04 AM
Answer

Nagendra Kumar Busam

Rank: Liferay Master

Posts: 636

Join Date: July 7, 2009

Recent Posts

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
April 25, 2012 3:05 PM
Answer

Andy Harb

Rank: Junior Member

Posts: 64

Join Date: October 22, 2009

Recent Posts

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
April 25, 2012 3:03 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

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
April 25, 2012 3:05 PM
Answer

Andy Harb

Rank: Junior Member

Posts: 64

Join Date: October 22, 2009

Recent Posts

Thanks for the correction! Edited original post