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 6865557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:04:09+00:00 2026-05-27T03:04:09+00:00

How to insert uploaded image from p:fileUpload as BLOB in MySQL? @Lob @Column(name =

  • 0

How to insert uploaded image from p:fileUpload as BLOB in MySQL?

@Lob
@Column(name = "photo")
private byte[] photo;

And in XHTML page, I write this:

<p:inputText value="#{condidat.condidat.photo}" >
<p:fileUpload fileUploadListener="#{fileUploadController.handleFileUpload}"   
    allowTypes="*.jpg;*.png;*.gif;" description="Images"/>                       
</p:inputText>

How can I retreive the value of uploaded file as byte[]?

  • 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-05-27T03:04:09+00:00Added an answer on May 27, 2026 at 3:04 am

    You can get the uploaded file content via FileUploadEvent. In PrimeFaces 4.x with Apache Commons FileUpload, or in PrimeFaces 5.x with context param primefaces.UPLOADER set to commons, you can use UploadedFile#getContents() to obtain the uploaded file as byte[].

    public void handleFileUpload(FileUploadEvent event) {
        byte[] content = event.getFile().getContents();
        // ...
    }
    

    In PrimeFaces 5.x with context param primefaces.UPLOADER absent or set to auto or native while using JSF 2.2, then getContents() will return null as that’s not implemented in NativeUploadedFile implementation. Use UploadedFile#getInputStream() instead and then read bytes from it, e.g. with help of commons IO.

    public void handleFileUpload(FileUploadEvent event) {
        byte[] content = IOUtils.toByteArray(event.getFile().getInputstream());
        // ...
    }
    

    Finally, just set this byte[] in your entity and persist/merge it.

    Make sure that you have set the form encoding type to multipart/form-data and, when using the Apache Commons FileUpload, that you have configured the file upload filter in web.xml as per PrimeFaces user guide.

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

Sidebar

Related Questions

I'm trying to save a file (pdf or image) uploaded from a form into
I want to insert uploaded image in root directory images folder and its path
INSERT INTO `images` (s_id, u_id, name, filename, filesize, uploaded) SELECT s_id, ?, ?, ?,
INSERT INTO [Tasks] ([LoginName] ,[Type] ,[Filter] ,[Dictionary] ,[Description]) Select N'Anonymous',4,'SomeTable.targetcode in (select Code from
INSERT INTO item_quotation (item_id, quotation_id,name_searched,item_name,other_name,selling_price,discounted_price) SELECT DISTINCT I.item_id, . $quotation_id . ,T.item_name, I.name,I.other_name, INV.selling_price,
My insert and update pages (through my admin forlder) into mysql stopped working. When
I am trying to INSERT INTO a table using the input from another table.
I'm building a file uploader that gets IPTC data from the image and inserts
Hope you all will be fine. Actually i want to upload image files from
i am trying to upload an image and saving image name in database as

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.