1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[OutSystems](Reactive Web App版)ブラウザ内にダウンロードしたファイルを表示する

Posted at

以前、別の記事Downloadでブラウザ内にダウンロードしたファイルを表示するでOutSystemsアプリケーションから出力したファイルを、(ローカルに保存するのではなく)ブラウザに表示する方法について検討しました。

そのときは、Reactive Web Appで実現する方法が見つからなかったのですが、この度実現する方法がわかったのでメモ。

元ネタ

以下のフォーラム投稿への返信
Reactive open PDF in browser instead of downloading it

you might need a workaround which is creating a rest endpoint that sends the file with the correct header so the browser opens it instead of downloading.

実装

Expose REST API

ここでは、ファイルをResourcesにおき、そのContent (Binary Data型)を出力変数に設定するREST API Methodを用意しました(下のDownloadPdfが該当)。
image.png

Assignでは単純に出力変数PdfにResourcesのpdfファイルの.Contentを設定しているだけ。
ここでは特に記述していませんが、実プロジェクトではセキュリティの判定が必要です。

Content-Type

ブラウザにファイルを開いてもらうためには、ファイル種類に応じた適切なContent-Typeを設定します。ここではPDFファイルなのでapplication/pdfを設定したい。

OutSystemsのExpose REST APIメソッドで任意のResponseヘッダを設定するにはHttpRequestHandler Extensionに含まれているAddHeader Actionを使います。

Responseヘッダに以下のような行を設定するには、

Content-Type: application/pdf

AddHeaderを以下のようにします。
image.png

JavaScriptを使ってREST APIのURLを開く

そのままです。
Reactive Web AppではScreen ActionにJavaScript要素を配置し、その中に任意のJavaScriptコードを書けます。

よって作成したREST APIのURLをwindow.openに渡してやればいいですね。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?