Good Day i have a database which allows the user to upload documents from the system and store the document on the sever which is access by a url as seen below.
Procedure
create or replace PROCEDURE blob_to_file (p_blob IN OUT NOCOPY BLOB,
p_dir IN VARCHAR2,
p_filename IN VARCHAR2)
AS
l_file UTL_FILE.FILE_TYPE;
l_buffer RAW(32767);
l_amount BINARY_INTEGER := 32767;
l_pos INTEGER := 1;
l_blob_len INTEGER;
BEGIN
l_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 LOOP
DBMS_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);
EXCEPTION
WHEN OTHERS THEN
-- Close the file if something goes wrong.
IF UTL_FILE.is_open(l_file) THEN
UTL_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;
Insert statement to table
DECLARE l_blob BLOB; VID NUMBER; BEGIN
select BLOB_CONTENT INTO l_blob FROM apex_application_temp_files
where NAME= :P48_BLOB_CONTENT ;
blob_to_file(p_blob => l_blob,
p_dir => 'STOCK_DIRECTORY',
p_filename => :P48_ATTACHMENT_NAME||'.pdf')
;
INSERT INTO ATTACHMENTS(ATTACHMENTS_ID, ATTACHMENT_NAME,CASE_ID,DATE_CREATED, MIME_TYPE,designation)
VALUES("ATTACHMENTS_SEQ".nextval,:P48_ATTACHMENT_NAME,:P48_CASE_ID,SYSDATE,'application/pdf','http://192.168.XXX.XXX:80/oracle_projects/dppcms/files/'||:P48_ATTACHMENT_NAME||'.pdf');
END;
What i will like however is to not move the document via the above procedure but to actual store in the attachment table the path of the original file.
so for example if a file is uploaded from the user my documents folder the path stored in the attachment table should show :c\users\mydocuments ect. instead of using the procedure to send it to http://192.168.XXX.XXX:80 etc