Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Upload image into blob field issue

Daniel B.Oct 30 2015 — edited Oct 30 2015

Hello experts,

I'm trying to upload an image via input File to convert it into a blob field and save it into the database afterwards.

So I binded the value from the input File to create the blob via bean I found at the internet.

My Page components binding:

<af:inputFile id="inputImage" value="#{UploadBean.file}"/>

<af:button text="Upload" id="btnUpload" action="#{UploadBean.uploadImage}"/>


My Bean:


private BlobDomain img;

private UploadedFile _file;

public UploadBean() {

    super();

}

public UploadedFile getFile() {

    return _file;

}

public void setFile(UploadedFile file) {

    _file = file;

}

public void uploadImage() {

    UploadedFile myfile = (UploadedFile)this.getFile();

      

    img = createBlobDomain(myfile);

    System.out.println(img);

}

private BlobDomain createBlobDomain(UploadedFile file) {

    InputStream in = null;

    BlobDomain blobDomain = null;

    OutputStream out = null;

    try {

        in = file.getInputStream();

          

        blobDomain = new BlobDomain();

        out = blobDomain.getBinaryOutputStream();

        byte[] buffer = new byte[8192];

        int bytesRead = 0;

          

        while ((bytesRead = in.read(buffer, 0, 8192)) != -1) {

            out.write(buffer, 0, bytesRead);

        }

        in.close();

    } catch (IOException e) {

        e.printStackTrace();

    } catch (SQLException e) {

        e.fillInStackTrace();

    }

  return blobDomain;

}

But it seems like that the file is still null after choosing an image, 'cause it throws the follwing error message:

<oracle.adf.common> <AdfDiagnosticsJarsVersionDumpImpl> <executeDump> <Pfad für den Dump der JAR-Version :C:\Users\user\AppData\Roaming\JDeveloper\system12.1.3.0.41.140521.1008\DefaultDomain\servers\DefaultServer\adr\diag\ofm\defaultdomain\defaultserver\incident\incdir_45/adf_DiagnosticsJarsVersionDump42_i45.txt>

<oracle.dfw.impl.incident.DiagnosticsDataExtractorImpl> <DiagnosticsDataExtractorImpl> <createADRIncident> <Ereignis 46 mit Problemschlüssel "ADFC-00032 [ADFc]" erstellt>

<oracle.adf.view> <RichExceptionHandler> <_logUnhandledException> <ADF_FACES-60098:Faces-Gültigkeitsdauer empfängt nicht behandelte Exceptions in Phase INVOKE_APPLICATION 5>

javax.faces.FacesException: #{UploadBean.uploadImage}: //C:/Users/user/AppData/Roaming/JDeveloper/system12.1.3.0.41.140521.1008/o.j2ee/drs/REA/ViewPflegeWebApp.war/de/test/viewpflege/pages/UploadPage.jsff @13,85 action="#{UploadBean.uploadImage}": java.lang.NullPointerException

...

What am I missing or doing wrong?

Uusing JDeveloper 12.1.3

Thanks!

This post has been answered by Habib Eslami on Oct 30 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 27 2015
Added on Oct 30 2015
1 comment
419 views