grant execute on utl_file to HRMS;CREATE OR REPLACE DIRECTORY STOCK_DIRECTORY AS 'C:\Program Files (x86)\Apache Software Foundation\Tomcat 9.0\webapps\i\IMAGE_STORE';
GRANT read, write ON DIRECTORY STOCK_DIRECTORY TO HRMS;
Create Procedure In Database :
CREATE OR REPLACE PROCEDURE HRMS.blob_to_file (p_blob IN OUT NOCOPY BLOB,p_dir IN VARCHAR2,p_filename IN VARCHAR2)ASl_file UTL_FILE.FILE_TYPE;l_buffer RAW(32767);l_amount BINARY_INTEGER := 32767;l_pos INTEGER := 1;l_blob_len INTEGER;BEGINl_blob_len := DBMS_LOB.getlength(p_blob);-- Open the destination file.l_file := UTL_FILE.fopen(p_dir, p_filename,'WB', 32767);-- Read chunks of the BLOB and write them to the file until complete.WHILE l_pos <= l_blob_len LOOPDBMS_LOB.read(p_blob, l_amount, l_pos, l_buffer);UTL_FILE.put_raw(l_file, l_buffer, TRUE);l_pos := l_pos + l_amount;END LOOP;-- Close the file.UTL_FILE.fclose(l_file);EXCEPTIONWHEN OTHERS THEN-- Close the file if something goes wrong.IF UTL_FILE.is_open(l_file) THENUTL_FILE.fclose(l_file);END IF;RAISE;/* WHEN UTL_FILE.invalid_operation THEN dbms_output.PUT_LINE('cannot open file invalid name');WHEN UTL_FILE.read_error THEN dbms_output.PUT_LINE('cannot be read');WHEN no_data_found THEN dbms_output.PUT_LINE('end of file');UTL_FILE.fclose(l_file);RAISE;*/END blob_to_file;/
Create Process To Insert Image
DECLAREl_blob BLOB;VID NUMBER;BEGINSELECT NVL(MAX(NVL(EMPLOYEE_ID,0)),0)+ 1 INTO VID FROM EMPLOYEE_INFORMATION_IMAGE ;
select BLOB_CONTENT INTO l_blob FROM apex_application_temp_fileswhere NAME= :P7_IMAGE ;blob_to_file(p_blob => l_blob,p_dir => 'STOCK_DIRECTORY',p_filename => VID||'.png');INSERT INTO EMPLOYEE_INFORMATION_IMAGE(EMPLOYEE_ID,EMPLOYEE_NAME,DESIGNATION,JOINING_DATE,FATHERS_NAME)VALUES(VID,:P7_EMPLOYEE_NAME,:P7_DESIGNATION,:P7_JOINING_DATE,:P7_FATHER_NAME);END;
how to grant utl_file to user
ReplyDeleteits show insufficient privilege
ReplyDeleteThanks for your comments.You have need to give full administrative permission to your computer user.
DeleteCan I update the image then it will store new image or replace it?
ReplyDeleteThanks bro for your valuable comments.
ReplyDeleteHow to do it without tomcat in standalone mode
ReplyDelete