Picture Uploading and Downloading Process from Intrective Grid
/********************* Pic Uploading Method ************************/
declare
l_file_names apex_t_varchar2;
l_file apex_application_temp_files%rowtype;
l_file_exists boolean := false;
begin
-- Create the collection only if it doesn't exist
if not apex_collection.collection_exists(p_collection_name=>'DOCUMENT') then
APEX_COLLECTION.CREATE_COLLECTION(
p_collection_name=>'DOCUMENT'
);
end if;
l_file_names := apex_string.split (
p_str => :P29_NEW,
p_sep => ':' );
for i in 1 .. l_file_names.count loop
select *
into l_file
from apex_application_temp_files
where name = l_file_names(i) and APPLICATION_ID=:APP_ID;
-- Check if the file already exists in the collection to prevent duplicates
for j in (select c001 from apex_collections where collection_name = 'DOCUMENT') loop
if j.c001 = l_file.FILENAME then
l_file_exists := true;
exit;
end if;
end loop;
if not l_file_exists then
APEX_COLLECTION.ADD_MEMBER(
p_collection_name => 'DOCUMENT',
p_c001 => l_file.FILENAME,
p_c002 => l_file.MIME_TYPE,
p_blob001 => l_file.BLOB_CONTENT,
p_n001 => l_file.ID,
p_d001 => sysdate );
end if;
-- Reset the flag for the next iteration
l_file_exists := false;
end loop;
commit;
end;
DECLARE
l_file_rec BLOB;
CURSOR c_collections IS
SELECT BLOB001 FROM APEX_COLLECTIONS WHERE COLLECTION_NAME = 'DOCUMENT';
BEGIN
FOR I IN c_collections LOOP
l_file_rec := I.BLOB001;
update test_images set img = l_file_rec where img_id = :P29_ID;
END LOOP;
COMMIT;
END;
IF apex_collection.collection_exists('DOCUMENT') THEN
begin
apex_collection.delete_collection(p_collection_name => 'DOCUMENT');
end;
end if;
declare
l_file_names apex_t_varchar2;
l_file apex_application_temp_files%rowtype;
l_file_exists boolean := false;
begin
-- Create the collection only if it doesn't exist
if not apex_collection.collection_exists(p_collection_name=>'DOCUMENT') then
APEX_COLLECTION.CREATE_COLLECTION(
p_collection_name=>'DOCUMENT'
);
end if;
l_file_names := apex_string.split (
p_str => :P29_NEW,
p_sep => ':' );
for i in 1 .. l_file_names.count loop
select *
into l_file
from apex_application_temp_files
where name = l_file_names(i) and APPLICATION_ID=:APP_ID;
-- Check if the file already exists in the collection to prevent duplicates
for j in (select c001 from apex_collections where collection_name = 'DOCUMENT') loop
if j.c001 = l_file.FILENAME then
l_file_exists := true;
exit;
end if;
end loop;
if not l_file_exists then
APEX_COLLECTION.ADD_MEMBER(
p_collection_name => 'DOCUMENT',
p_c001 => l_file.FILENAME,
p_c002 => l_file.MIME_TYPE,
p_blob001 => l_file.BLOB_CONTENT,
p_n001 => l_file.ID,
p_d001 => sysdate );
end if;
-- Reset the flag for the next iteration
l_file_exists := false;
end loop;
commit;
end;
DECLARE
l_file_rec BLOB;
CURSOR c_collections IS
SELECT BLOB001 FROM APEX_COLLECTIONS WHERE COLLECTION_NAME = 'DOCUMENT';
BEGIN
FOR I IN c_collections LOOP
l_file_rec := I.BLOB001;
update test_images set img = l_file_rec where img_id = :P29_ID;
END LOOP;
COMMIT;
END;
IF apex_collection.collection_exists('DOCUMENT') THEN
begin
apex_collection.delete_collection(p_collection_name => 'DOCUMENT');
end;
end if;
/************************** Downloading Method **************************/
declare
cnt number;
l_files_rec TEST_IMAGES%rowtype;
begin
select nvl(dbms_lob.getlength(img),0) into cnt from test_images where img_id = :P30_FILE_ID;
if cnt <> 0 then
select *
into l_files_rec
from TEST_IMAGES
where IMG_ID = :P30_FILE_ID;
-- owa_util.mime_header(l_files_rec.mime_type, false);
htp.p('Content-Length: ' || dbms_lob.getlength(l_files_rec.img));
htp.p('Content-Disposition: attachment; filename="' || l_files_rec.img_name || '"');
owa_util.http_header_close;
wpg_docload.download_file(l_files_rec.img);
apex_application.stop_apex_engine;
end if;
end;