元ブログの内容をAPEX 22.2のActionインターフェースを使う実装に変えています。
ダウンロード・リンクと同様に、仮想列をリージョンBucket Contentsに追加します。手順は同じです。
仮想列DERIVED$02が作成されるので、その識別のタイプとしてプレーン・テキストを指定し、式の書式のHTML式に以下を設定します。
カスタム属性data-ationからアクションdelete-objectを呼び出すように定義しています。引数nameとしてオブジェクト名を渡しています。
識別の名前としてDELETE_OBJECT(この名前で処理が呼び出されるので必ずDELETE_OBJECTを指定してください)、識別のタイプはコードを実行、ソースの位置はローカル・データベースで、PL/SQLコードとして以下を記述します。元のブログのコードは日本語の扱いに不備があったので、その部分を修正しています。
オブジェクトを削除するリンクの追加
ダウンロード・リンクと同様に、仮想列をリージョンBucket Contentsに追加します。手順は同じです。
仮想列DERIVED$02が作成されるので、その識別のタイプとしてプレーン・テキストを指定し、式の書式のHTML式に以下を設定します。
アクションdelete-objectを定義します。以下のコードを、ページ・プロパティのJavaScriptのページ・ロード時に実行に記述します。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apex.actions.add([ | |
{ | |
name: "delete-object", | |
action: function( event, element, args ) { | |
apex.message.confirm( | |
"Are you sure?", | |
(okPressed) => { | |
if (okPressed) { | |
let result = apex.server.process( | |
"DELETE_OBJECT", | |
{ | |
x01: $v("P1_BUCKET_NAME"), | |
x02: args.name | |
} | |
); | |
result.done( | |
(data) => { | |
apex.message.showPageSuccess( | |
'Object deleted successfully.', | |
); | |
apex.event.trigger( | |
"#R_BUCKET_CONTENTS", | |
"apexrefresh" | |
); | |
} | |
).fail( | |
(jqXHR, textStatus, errorThrown) => { | |
apex.message.alert('Failed to delete object.'); | |
} | |
); | |
} | |
} | |
) | |
} | |
} | |
]); |
リージョンBucket Contentsの詳細の静的IDとしてR_BUCKET_CONTENTSを設定します。リフレッシュ対象のリージョンを指定するために使用します。
Ajaxのコールバックを作成するため、左ペインの表示にプロセス・ビューを選んで、Ajaxコールバックの上でコンテキスト・メニューを開き、プロセスの作成を実行します。
識別の名前としてDELETE_OBJECT(この名前で処理が呼び出されるので必ずDELETE_OBJECTを指定してください)、識別のタイプはコードを実行、ソースの位置はローカル・データベースで、PL/SQLコードとして以下を記述します。元のブログのコードは日本語の扱いに不備があったので、その部分を修正しています。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare | |
c_bucket_name apex_application.g_x01%type := | |
apex_application.g_x01; | |
c_object_name apex_application.g_x02%type := | |
apex_application.g_x02; | |
l_request_url varchar2(32767); | |
l_response clob; | |
begin | |
l_request_url := :G_BASE_URL || 'b/' || c_bucket_name | |
|| '/o/' || utl_url.escape(c_object_name, false, 'AL32UTF8'); | |
l_response := apex_web_service.make_rest_request( | |
p_url => l_request_url | |
, p_http_method => 'DELETE' | |
, p_credential_static_id => :G_OCI_WEB_CREDENTIAL | |
); | |
if apex_web_service.g_status_code != 200 then | |
owa_util.status_line( | |
nstatus => apex_web_service.g_status_code | |
); | |
sys.htp.p('{ "message": "Failed" }'); | |
else | |
sys.htp.p('{ "message": "Success" }'); | |
end if; | |
end; |
アプリケーションを実行して、ファイルのアップロード、ダウンロード、削除などを実行してみましょう。
また、元となるブログの内容はここで終了です。
今回作成したアプリケーションのエクスポートを以下に置きました。
https://github.com/ujnak/apexapps/blob/master/exports/apex-with-oci-object-storage.zip
Oracle APEXのアプリケーション作成の参考になれば幸いです。
完