please Sergey you can complete my code ???? read at 1) and 2) and 3)
comment ...
1) i not have not declared any @Produce at retod that Stream the image ,
because i would set into the code because it can be a image/jpg, image/bmp,
image/gif, ,image.png , and many other type .
The content typoe it is saved into the db when i save the image with JPA
into DB .
2) how i write the bytes into resposne?
3) how i set the contenttype that i get from entityJPA?
package myrest.mauro;
import java.io.*;
import javax.inject.Inject;
import javax.ws.rs.Path;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.StreamingOutput;
import myrest.mauro.ImageEntityJPA;
import myrest.mauro.MyDAO;
/**
*
* @author utente_javaee7
*/
@Path("/imagefromdb")
public class SearchImageFromDB {
@Inject MyDAO myDAO;
@GET
// 1) i not have declared any @Produces
@Path("/{id}")
public Response hello(@PathParam("Id") long Id) {
ImageEntityJPA myimage =myDAO.getImageEntityJPAFromId(Long
id)
byte[] bytesfromdb= myimage.getBytesimage();
String contenttype= myimage.getContenttype();
ByteArrayOutputStream baos= new ByteArrayOutputStream (bytesfromdb);
StreamingOutput stream = new StreamingOutput() {
@Override
public void write(OutputStream os) throws IOException,
WebApplicationException {
// 2) how write the bytes of image??????????
}
};
// 3) how set the content type that i get form entityJPA?
return Response.ok(stream).build();
}
}
2014-04-22 11:05 GMT+02:00 Sergey Beryozkin [via CXF] <
[email protected]>:
> Hi
>
> Have you resource method returning the implementation of
>
>
> https://jax-rs-spec.java.net/nonav/2.0/apidocs/javax/ws/rs/core/StreamingOutput.html
>
> CXF 3.0.0 (released in the next couple of weeks) has introduced
>
>
> https://git-wip-us.apache.org/repos/asf?p=cxf.git;a=blob;f=rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/StreamingResponse.java,
>
>
> a typed analog of StreamingOutput, I will document it shortly
>
> But using StreamingOutout for returning the file should work perfectly
> well
>
> Cheers, Sergey
>
>
>
> On 17/04/14 18:16, mauro2java2011 wrote:
>
> > Hi all. i would get a image from a db .
> > I get the bytes[] of image and the content.type saved into db with JPA
> .
> > But next how i can stream into the Response for show into a web page ?
> >
> > i have found example for save the file with saveas ...
> >
> > But i would stream the bytes , not save the file on client .
> >
> > Please some code or link of tutorial?
> > tank you
> > mauro
> >
> >
> >
> >
> > --
> > View this message in context:
> http://cxf.547215.n5.nabble.com/how-get-a-image-from-db-with-rest-cxf-tp5743013.html
> > Sent from the cxf-user mailing list archive at Nabble.com.
> >
>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>
> Blog: http://sberyozkin.blogspot.com
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://cxf.547215.n5.nabble.com/how-get-a-image-from-db-with-rest-cxf-tp5743013p5743085.html
> To unsubscribe from how get a image from db with rest-cxf?, click
> here<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5743013&code=bWF1cm8yamF2YTIwMTFAZ21haWwuY29tfDU3NDMwMTN8LTExMTcxODc2MjU=>
> .
> NAML<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
--
View this message in context:
http://cxf.547215.n5.nabble.com/Re-how-get-a-image-from-db-with-rest-cxf-tp5743093.html
Sent from the cxf-user mailing list archive at Nabble.com.