ファイル名に変数を使用してダウンロードしたファイルの名前を設定すると、変数が表示されません。しかし、ファイル名に変数を使用しない場合は、必要に応じて名前を設定します。この方法でsetHeaderはファイル名を変更しません
response().setHeader("Content-disposition", "attachment; filename=testName.pdf");
、ダウンロードしたファイルの名前は、私は、変数とそれを使用するには、3つの異なる方法を試してみましたtestName.pdf
です。
response().setHeader("Content-disposition", "attachment; filename="+ fileName.toString() +".pdf");
または
..... "attachment; filename="+ fileName +".pdf");
または
..... "attachment; filename="+ fileName.toString() +".pdf");
全コード:
public static Result download(String id) throws IOException {
Get g = new Get(Bytes.toBytes(id));
g.addColumn(Bytes.toBytes("content"), Bytes.toBytes("raw"));
g.addColumn(Bytes.toBytes("book"), Bytes.toBytes("title"));
HTable hTable = new HTable(hConn.config, "books");
org.apache.hadoop.hbase.client.Result result = hTable.get(g);
if (result.containsColumn(Bytes.toBytes("content"), Bytes.toBytes("raw"))){
byte[] rawBook = result.getNoVersionMap().get(Bytes.toBytes("content")).get(Bytes.toBytes("raw"));
byte[] fileName = result.getNoVersionMap().get(Bytes.toBytes("book")).get(Bytes.toBytes("title"));
response().setContentType("application/octet-stream");
response().setHeader("Content-disposition", "attachment; filename=\"" + fileName + "\".pdf");
return ok(rawBook);
}
return notFound();
}
だから、これはJavaのプレイフレームワークからです。データベースはHBaseです。私はbooks
と呼ばれる1つのテーブルを持っており、それは2つのファミリーcontent
とbook
を持っています。 content
にはpdf(バイト単位)の内容が含まれ、book
にはpdf(タイトル、ページ番号、著者など)のプロパティが含まれています。 Row Key
はcontent
とbook
の両方が同じです。
変数を使用してファイル名を設定する別の方法がありますか、または何か不足していますか?
はいあなたは正しかったです。私は[B @を得ていた...ありがとうございました。 –