Legacy Knowledge Base
Published Jul. 2, 2025

"PortalException: Unable to get a unique file name" when adding a new Blogs image

Written By

Roberto Díaz

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

  • Steps to reproduce:
    1. Add a new blogs entry
    2. Add a new cover image to this blogs entry
    3. Save the entry
  • Expected behavior: The image is uploaded
  • Current behavior: An error is thrown and you found an error similar to this in your logs:
ERROR com.liferay.blogs.web.internal.portlet.action.EditEntryMVCActionCommand - com.liferay.portal.kernel.exception.PortalException: Unable to get a unique file name for image.png in folder 75309953
com.liferay.portal.kernel.exception.PortalException: Unable to get a unique file name for image.png in folder 75309953
at com.liferay.portlet.blogs.BlogsEntryAttachmentFileEntryHelper.getUniqueFileName(BlogsEntryAttachmentFileEntryHelper.java:206)
at com.liferay.portlet.blogs.BlogsEntryAttachmentFileEntryHelper.addBlogsEntryAttachmentFileEntry(BlogsEntryAttachmentFileEntryHelper.java:100)
at com.liferay.portlet.blogs.BlogsEntryAttachmentFileEntryHelper.addBlogsEntryAttachmentFileEntries(BlogsEntryAttachmentFileEntryHelper.java:55)
at com.liferay.blogs.web.internal.portlet.action.EditEntryMVCActionCommand.updateEntry(EditEntryMVCActionCommand.java:548)
at com.liferay.blogs.web.internal.portlet.action.EditEntryMVCActionCommand$UpdateEntryCallable.call(EditEntryMVCActionCommand.java:677)
at com.liferay.blogs.web.internal.portlet.action.EditEntryMVCActionCommand$UpdateEntryCallable.call(EditEntryMVCActionCommand.java:673)
at com.liferay.portal.spring.transaction.TransactionInvokerImpl$CallableMethodInvocation.proceed(TransactionInvokerImpl.java:101)
at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:54)
at com.liferay.portal.spring.transaction.TransactionInvokerImpl.invoke(TransactionInvokerImpl.java:47)
at com.liferay.portal.kernel.transaction.TransactionInvokerUtil.invoke(TransactionInvokerUtil.java:28)
at com.liferay.blogs.web.internal.portlet.action.EditEntryMVCActionCommand.doProcessAction(EditEntryMVCActionCommand.java:192)
at com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCActionCommand.processAction(BaseMVCActionCommand.java:61)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.callActionMethod(MVCPortlet.java:380)
at com.liferay.portal.kernel.portlet.LiferayPortlet.processAction(LiferayPortlet.java:93)
at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.processAction(MVCPortlet.java:260)

Environment

  • 7.0+

Resolution

  • Blogs attachments are stored in a common folder. Because of that, Liferay handles the name collision adding a suffix to the files if a used name is detected.
  • Anyway, to avoid performance problems, we limit this autogenerated names to 50.
  • To confirm if that's your case you could run a script similar to CheckBlogsUniqueFileNameLogic.groovy, based in the BlogsEntryLocalServiceImpl#getUniqueFileName method logic (it could differ depending on the Liferay version).
  • You only have to adjust this variables to the proper ones:
    def groupId = [group id]L
    def fileName = "[name of the file]"
    def folderId = [folder id]L
  • And execute it.
  • Once it is done, you could see detailed info of the process with the exception at the end.
  • If you find that you reach the 50 elements limit before the Exception is thrown...
    image (50).png
  • ...then you've confirm that you've reach the file name autogeneration limit.
  • To solve (or avoid) the problem you could remove the unused images or avoid using this name in the future.
  • Our suggestion is try to use the most descriptive image name in all the cases to minimize the collisions.
  • Due it has impact in the performance, we do not recomend to customize this limit.

Additional Information

 

 

 

Did this article resolve your issue ?

Legacy Knowledge Base