1. 자바스크립트로 다운 받기
몇 가지 형태의 코드를 실행 해 봤지만 파일 다운로드는 되지 않고 직접 브라우저에서 창이 오픈됨.
var vPIC1 = document.getElementById("P9_PIC1").src;
//$('a#P9_PIC1').attr({target: '_blank', href : vPIC1});
//$('a#P9_PIC1').click();
/*
var element = document.createElement('a');
element.setAttribute('download', vPIC1);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
const fileName = vPIC1.split('/').pop();
var el = document.createElement("a");
el.setAttribute("href", vPIC1);
el.setAttribute("download", fileName);
document.body.appendChild(el);
el.click();
el.remove();
*/
아마도 이것이 문제인듯.
In the latest versions of Chrome, you cannot download cross-origin files (they have to be hosted on the same domain)
2. 서버스크립트로 다운 받기
1) 버튼 생성
Identification - Button Name : BTN_DOWN
Behavior - Action : Defined by Dynamic Action
Dynamic Action : DA_BTN_DOWN
When - Event : Click
Selection Type : Button
아래와 같이 구현하게된 이유는 1초 간격으로 SetTimeout 지정을 위함이고 그렇게 해야 두 번째, 세 번째 파일이 다운이 진행이 됨, SetTimeout이 없는 경우에는 여러 파일이 있어도 한 번만 실행이 되는 문제가 있고. window.open 일 경우는 새 창으로 열리기 때문에 브라우저에서 새창 오픈과 닫기가 진행되어 깜빡거리는 현상이 보임.
var vPIC1, vPIC2, vPIC3, vPIC4, vPIC5, vPIC6;
var vPICID = apex.item("P9_PICID").getValue();
if (document.getElementById("P9_PIC1")) { vPIC1 = document.getElementById("P9_PIC1").src; }
if (document.getElementById("P9_PIC2")) { vPIC2 = document.getElementById("P9_PIC2").src; }
if (document.getElementById("P9_PIC3")) { vPIC3 = document.getElementById("P9_PIC3").src; }
if (document.getElementById("P9_PIC4")) { vPIC4 = document.getElementById("P9_PIC4").src; }
if (document.getElementById("P9_PIC5")) { vPIC5 = document.getElementById("P9_PIC5").src; }
if (document.getElementById("P9_PIC6")) { vPIC6 = document.getElementById("P9_PIC6").src; }
var l_url = 'f?p=#APP_ID#:68:#SESSION#::NO:RP,68:P68_PICID,P68_PICNO:#PICID#,';
l_url = l_url.replace('#APP_ID#', $v('pFlowId'));
l_url = l_url.replace('#SESSION#', $v('pInstance'));
l_url = l_url.replace('#PICID#', vPICID);
if (!vPIC1) return;
apex.server.process(
'DA-popup',
{x01: l_url+"PIC1"},
{success: function (pData) {
pData = pData.replace(",this", ",'#btnOpenDialogPIC1'");
apex.navigation.redirect(pData);
},
dataType: "text"
}
);
if (!vPIC2) return;
apex.server.process(
'DA-popup',
{x01: l_url+"PIC2"},
{success: function (pData) {
pData = pData.replace(",this", ",'#btnOpenDialogPIC2'");
setTimeout(function() {
apex.navigation.redirect(pData);
}, 1000);
},
dataType: "text"
}
);
...
...
...
if (!vPIC6) return;
apex.server.process(
'DA-popup',
{x01: l_url+"PIC6"},
{success: function (pData) {
pData = pData.replace(",this", ",'#btnOpenDialogPIC6'");
setTimeout(function() {
apex.navigation.redirect(pData);
}, 5000);
},
dataType: "text"
}
);
2) Page 68
Pre-Rendering - Before Header Processes
Identification - Name : DownloadObject
Type : Execute Code
Source - Location : Local Database
Language : PL/SQL
declare
l_request_url varchar2(32767);
l_content_type varchar2(32767);
l_content_length varchar2(32767);
l_response blob;
l_filename varchar2(1000);
download_failed_exception exception;
begin
for c1 in (select decode(:P68_PICNO, 'PIC1', pic1, 'PIC2', pic2, 'PIC3', pic3, 'PIC4', pic4, 'PIC5', pic5, 'PIC6', pic6) pic
from po_mst_pic where pic_id = :P68_PICID)
loop
l_request_url := c1.pic;
l_filename := substr(l_request_url, instr(l_request_url, '/', -1)+1);
apex_web_service.g_request_headers.delete();
l_response := apex_web_service.make_rest_request_b(
p_url => l_request_url
, p_http_method => 'GET'
);
if apex_web_service.g_status_code != 200 then raise download_failed_exception; end if;
for i in 1..apex_web_service.g_headers.count
loop
if apex_web_service.g_headers(i).name = 'Content-Length' then
l_content_length := apex_web_service.g_headers(i).value;
end if;
if apex_web_service.g_headers(i).name = 'Content-Type' then
l_content_type := apex_web_service.g_headers(i).value;
end if;
end loop;
sys.htp.init;
if l_content_type is not null then
sys.owa_util.mime_header(trim(l_content_type), false);
end if;
sys.htp.p('Content-length: ' || l_content_length);
sys.htp.p('Content-Disposition: attachment; filename="' || l_filename || '"' );
sys.htp.p('Cache-Control: max-age=3600'); -- if desired
sys.owa_util.http_header_close;
sys.wpg_docload.download_file(l_response);
apex_application.stop_apex_engine;
end loop;
end;
![](https://blogger.googleusercontent.com/img/a/AVvXsEhepePqZx1m-Sa5_VK9vr8vQBEaVDRCmhXnq3SNEjM5570Wf-9WOI1VKV8ohj2Zemk7clWbhBTjNVVk9Fnltyj9s3aD28JCZ4XDs1PgPLWTFpLgmB7ZpjMQJbUClAImnqYVqNbfPw7r2EB0F_DcMLFP6ZugslYLVs16haERQ91hxvDolUQZl9B_uHjTcg=s320)
참고
https://gomakethings.com/how-to-force-a-file-to-download-instead-of-open-in-the-browser-using-only-html/
댓글 없음:
댓글 쓰기