Search This Blog

Wednesday, May 23, 2018

Download Text File With Unlimited Character



1. Make a Region with PL/SQL Dynamic Content  type .
==========
2. Assign ID to the region using  HTP.p (<span id="TEST_ID">) and Select data from table into  a  CLOB Type Variable  and Print the variable using HTP.p
==========
Example :

HTP.p ('<a download="Subject_Info.txt" id="downloadlink"  ><b>Download</b></a> <br> <br> <br>');  

DECLARE
  
   v_text     CLOB;
BEGIN
HTP.p ('<span id="TEST_ID">');      
      FOR i
         IN (SELECT    EMPLOYEE_ID  -- Select data from table
                 || FIRST_NAME
                 || LAST_NAME
                 || JOB
                 || HIRE_DATE
                 || SALARY
                 || DEPARTMENT_ID
                    AS Alias
            FROM EMPLOYEES )
      LOOP
  v_text := i."Alias";
         
      /*   HTP.p ('' || replace(v_text,'&amp;','&') || '');*/
     HTP.p (''|| replace (replace (UPPER(v_text), chr (13), ''), chr (10), ' ')|| '');
       
      END LOOP;

      HTP.p ('</span>');

END;



3.Copy Pest the JavaScript code into Page >> Function and Global Variable Declaration
==========

(function () {
    var textFile = null,
    makeTextFile = function (text) {
    var data = new Blob([text], {type: 'text/plain'});
    if (textFile !== null) {
    window.URL.revokeObjectURL(textFile);}
    textFile = window.URL.createObjectURL(data);
    return textFile;};
    var create = document.getElementById('create'),
    textbox = document.getElementById('TEST_ID'); 

    var link = document.getElementById('downloadlink');
    link.href =          makeTextFile(textbox.innerHTML.replace(/&amp;/g,"&").trim());
    link.style.display = 'block';

})();




Click On Download




5 comments:

  1. Hi, Qaium i am facing issue that it is downloading the div container as well.

    ReplyDelete
  2. Have you ever done this where code is executed from an Apex button? How would you do it?

    ReplyDelete
  3. Have you ever done this where code is executed from an Apex button? How would you do it?

    ReplyDelete
  4. I also need to keep all the CHR(13) and CHR(10). Text File is a fixed record length file with line breaks at the end

    ReplyDelete
  5. Hi there, I am trying your functionality but unable to, I am using oracle apex 5.0; when i check the browser its giving unable to get inner text error and on my apex page the download link is not clickable when i place the mouse cursor on it. Can you please share your inputs on what might be causing this issue. Thanks, Raghu

    ReplyDelete

Restrict File Upload by File Type in Oracle Apex

If you want to restrict file upload by file type/extension/format you can follow the below steps.  Goto File Browser Item --> Advanced --...