PDFファイルをブロブとして保存しました。ブラウザーでPDFとしてレンダリングしようとすると、次のようになります。
%PDF-1.4 %���� 5 0 obj <>stream x��[]s�6}
これは、私が使用しているコントローラーでの私のアクションです def showDetails = {
def product = Sample.get(params.id)
response.contentType = 'application/pdf'
response.setHeader('Content-disposition', 'attachment; filename=file.pdf')
response.getOutputStream().write(product.file)
response.getOutputStream().flush()
}
私も追加しようresponse.characterEncoding = "utf 8"
としましたが、それもうまくいきませんでした。
明確にするために:PDFファイルをブロブとして保存するフォームがあります。オブジェクトがデータベースに保存されると、オブジェクトといくつかのパラメーター (名前、日付など) がアプリに表示されます。名前をクリックすると、div 内の blob ファイルへのリンクが表示されます。
<g:remoteLink id="${s.id}" update="details" controller="submitSample"action="showDetails" >${s.sampleNameID}</g:remoteLink></td>
このように getOutputStream を getBytes() に変更すると、次のエラーが発生します。
No signature of method: [B.getBytes() is applicable for argument types: () values: []
可能な解決策: getClass()、getAt(groovy.lang.ObjectRange)、getAt(java.lang.Integer)、getAt(groovy.lang.IntRange)、getAt(java.lang.String)、getAt(groovy.lang.Range) )。
単純に product.file を使用すると、出力が文字化けします。