3

Java サーバー (Restful Jax-rs) から画像を送信したい。私のクライアントは Android です。

@GET
public Response getUserImage() {
byte[] image =new byte[1024];
return Response.ok(image, MediaType.APPLICATION_OCTET_STREAM).header("content-attachment; filename=image_from_server.png") .build();

しかし、ここに 1 つのダウンロード ボックスが来ています。ダウンロードボックスなしでダウンロードしたいので、ブラウザでリクエストURLを実行すると、自動的に開くはずです。ありがとう。

4

2 に答える 2

9

あなたが指定したからだと思いますapplication/octet-stream

image/jpegまたはを使用する必要があると思いますimage/png

@GET
@Produces({"image/png"})
public Response getUserImage() {

    final byte[] image = ...;
    // say your image is png?

    return Response.ok().entity(new StreamingOutput(){
        @Override
        public void write(OutputStream output)
           throws IOException, WebApplicationException {
           output.write(image);
           output.flush();
        }
    }).build();
}
于 2012-06-26T15:58:41.913 に答える