Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8697891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:37:26+00:00 2026-06-13T01:37:26+00:00

When developing a Liferay portlet, sometimes you want to use file artifacts. For example,

  • 0

When developing a Liferay portlet, sometimes you want to use file artifacts. For example, you might want to have a configurable image(s), or the means to let users attach files to your custom service entity.

There are several API’s built into Liferay that address this problem. How is each one used?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:37:28+00:00Added an answer on June 13, 2026 at 1:37 am

    Following are the three methods which I can think of to store and retrieve files.


    Method-1

    Storage:
    Method using the DLStoreUtil as you have shown in your question.

    Retrieval:
    For this you need to get the file as a stream and then send it to the browser using the following code:

    String path = fileName;
    // if there is a directory then path would be
    // String path = "mydirectory/mySubDirectory/" + fileName; // mydirectory/mySubDirectory/my_File_image_name.png
    
    InputStream inputStream = DLStoreUtil.getFileAsStream(companyId(), CompanyConstants.SYSTEM, path);
    
    long contentLength = DLStoreUtil.getFileSize(companyId(), CompanyConstants.SYSTEM, path);
    
    String contentType = MimeTypesUtil.getContentType(fileName);
    
    ServletResponseUtil.sendFile(request, response, fileName, inputStream, contentLength, contentType);
    

    Liferay uses the above method for downloading attachments for its Message Boards portlet. You can check-out the source code here. I have not tried this but I suppose you can write this code in the serveResource method of your portlet and then provide the resourceURL as the URL to download or use it in the <img> tag.


    Method-2: Using DLAppService

    If you use this method there would be a database entry in the DLFileEntry table for this file and also the file will appear in the Documents & Media portlets.

    Storage:
    Example code to add a file:

    FileEntry = DLAppServiceUtil.addFileEntry(repositoryId, folderId, sourceFileName, mimeType, title, description, changeLog, bytes, serviceContext);
    

    You can check-out other methods and classes here.

    Retrieval:
    This is as explained in this answer.


    Method-3: Using ImageLocalService (Specifically for Images)

    For this method you will need to store the ImageID somewhere for later retrieval of the image.

    Storage:
    The following is a method to add/update an Image in liferay:

    // to Add an image
    long imageID = 0;
    imageID = CounterLocalServiceUtil.increment();
    ImageLocalServiceUtil.updateImage(imageID, bytes);
    
    // to update the same image, pass the existing Image ID
    ImageLocalServiceUtil.updateImage(existingImageID, bytes);
    

    Retrieval:

    You can write the following code in your JSP:

    <img alt="My Image"
         id="myImgID"
         title="This my image stored in liferay"
         src="<%=themeDisplay.getPathImage()%>/any_string_will_do_?img_id=<%=myImageId%>&img_timestamp=<%=someTimestampOrRandomString %>" />
    

    Note:
    img_timestamp=<%=someTimestampOrRandomString %>", This string is an optional parameter & can be skipped.
    This is used so that the browser retrieves the image from the server and not from the browser cache, everytime the page is refreshed.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a liferay portlet. Here is my code in jsp file: <table class=DDGridView>
I am developing Liferay portlet. The portlet should load xml file from same server
Hi i am developing Liferay faces portlet in Liferay 6.0.6 portal + 6.1 Plugins
There is a guide on the Liferay site Developing a Portlet with Multiple Actions
Developing for Android 2.3, I have a question regarding layouts. I use a vertival
I'm developing a JSF 2.0 portlet for Liferay 6.0.6 (Plugins SDK 6.1) and I
I am developing a theme for liferay,but liferay caching system does not let me
I am developing a portal to Liferay and want to apply there a Single
I am developing a Portlet with Liferay (using liferay-ui in the JSP) and SpringMVC.
developing iphone app, I have used a UIImageview and i have set an image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.