0

I'm new of vaadin and I'm developing my first application with spring and vaadin.

Now I'm trying to save an image inside my database. I followed the description of upload component on vaadin-book (Upload Component)

What do I have to change if I want to store it in the database? Can you give me an example?

1 Answer 1

1

The upload component writes the received data to an java.io.OutputStream so you have plenty of freedom in how you can process the upload content

If you want to store it as a large object, you can write directly as the stream comes in. See large object support.

If you want to store it as bytea in a row, you must accumulate it in memory then pass it to a parameterized query with setObject(parameterIndex, myDataBuffer, Types.BLOB) . This will consume several times the object's size in memory, so bytea is really only well suited to smaller data.

Sign up to request clarification or add additional context in comments.

2 Comments

Can give me an example on like i can use java.io.OutputStream directly. For the moment I'm saving the image in this mode: bFile = newbyte[(int)file.length()]; FileInputStream inputStream = new FileInputStream(file); inputStream.read(bFile); return bfile;
@Marco Not without knowing whether you're trying to store it as a large object or as bytea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.