2016-09-11 5 views
0

ベース64形式で画像を読み込む際に少し問題があります。私はフロントエンドでbase64の画像をrestサービスからimg srcタグに戻す

<img src="/path/to/rest/image">

残りサービスが表す:

@GET 
@PublicResource 
@Produces("image/*") 
@Path("/path/to/rest/image") 
public Response getResource() { 

    CacheControl cacheControl = new CacheControl(); 
    cacheControl.setMaxAge(86400); 
    cacheControl.setPrivate(true); 
    //image.imputStream() is the stream of the image's base64 representation 
    Response.ok(image.getInputStream())).cacheControl(cacheControl) 
        .header("Cache-Control", "max-age=86400").build(); 
} 

それが正しいBASE64を返し、私はパーサの画像にそれを解析するときに画像を示しています。しかしimgタグはまだ画像が壊れていることを示しています。 これを修正する方法はありますか?おそらく私はいくつかのヘッダーを追加する必要があります。

答えて

0

プリペンド64をベースに次のテキストは、私はすでにそれを持っているRESTサービス

data:image/png; base64, 
+0

から返されました。 – user3568791

+0

画像はJPEG以外の種類の画像である可能性があります。 –

+0

データを確認してください:image/png; base64、iVBORw0KGgoAAAAN ...これはpngです。 – user3568791

関連する問題