如何将BLOB图像复制到文件系统
我已经在这里建议如何将BLOB图像复制到文件系统
https://softwareengineering.stackexchange.com/questions/362992/all-images-on-a-single-table-is-a-good-idea/363007#363007
要存储在文件系统中的图像,而不是如表BLOB。
如何将BLOB复制到文件中,并获取他的路径(将由APEX应用程序访问)?
我想制作一个触发器,将BLOB图像保存到文件系统,并将路径保存到varchar列。
表中有像
CREATE TABLE "ALLIMAGES_TBL" ( "ID" NUMBER NOT NULL ENABLE,
"NAME" NVARCHAR2(400),
"FILENAME" VARCHAR2(350 BYTE),
"MIME_TYPE" VARCHAR2(255 BYTE),
"SIZE" NUMBER,
"CHARSET" VARCHAR2(128 BYTE),
"LAST_UPDATE_DATE" DATE,
"BinaryBLOB" BLOB,
"PATH" varchar(260),
回答:
像往常一样的结构,有亲和禁忌两个选项:保持图像的数据库,或者让他们在一个文件系统。在我看来,如果只有几个(好吧,让我们来测量它们在100秒内),我宁愿把它们放在桌子上。处理它们更容易。因为,一旦他们在文件系统中,您必须使用一些更多(HTML)代码来获取&在Apex中显示它们。无论如何,这里是我如何做到这一点(在以前的Apex版本中,我相信它是4.0):使用“文件浏览”项我暂时将图像存储到表中(这是WWW_FLOW_FILES;您宁愿使用现在你自己的表格),然后 - 在按下按钮的过程中 - 我将它们移动到一个目录中。
过程代码:
declare -- l_dest_dir is name of the directory (Oracle object) which points
-- to a filesystem directory
l_dest_dir varchar2(30) := pkg_slike.f_dir_slike_upload_dp(:P0_DP);
begin
for cur_r in (select id, filename
from wwv_flow_files
where upper(filename) like 'TS%.JP%G'
)
loop
-- put a picture into L_DEST_DIR
pkg_slike.p_write_blob_to_file(cur_r.id, l_dest_dir);
delete from wwv_flow_files
where id = cur_r.id;
end loop;
end;
程序代码:
PROCEDURE p_write_blob_to_file (p_file_id IN NUMBER, p_dir IN VARCHAR2) IS
/* 19.04.2012. Taken from Eddie Awad's Blog
http://awads.net/wp/2011/09/20/create-an-application-to-upload-files-using-oracle-apex-in-less-than-10-minutes-video/
*/
l_blob BLOB;
l_blob_length INTEGER;
l_out_file UTL_FILE.file_type;
l_buffer RAW (32767);
l_chunk_size BINARY_INTEGER := 32767;
l_blob_position INTEGER := 1;
l_file_name pkg_general.subt_ime_slike;
BEGIN
-- Retrieve the BLOB for reading
SELECT blob_content, filename
INTO l_blob, l_file_name
FROM wwv_flow_files
WHERE id = p_file_id;
-- Retrieve the SIZE of the BLOB
l_blob_length := DBMS_LOB.getlength (l_blob);
-- Open a handle to the location where you are going to write the BLOB
-- to file.
-- NOTE: The 'wb' parameter means "write in byte mode" and is only
-- available in the UTL_FILE package with Oracle 10g or later
l_out_file :=
UTL_FILE.fopen (p_dir,
l_file_name,
'wb' -- important. If ony w then extra carriage return/line brake
,
l_chunk_size);
-- Write the BLOB to file in chunks
WHILE l_blob_position <= l_blob_length
LOOP
IF l_blob_position + l_chunk_size - 1 > l_blob_length
THEN
l_chunk_size := l_blob_length - l_blob_position + 1;
END IF;
DBMS_LOB.read (l_blob,
l_chunk_size,
l_blob_position,
l_buffer);
UTL_FILE.put_raw (l_out_file, l_buffer, TRUE);
l_blob_position := l_blob_position + l_chunk_size;
END LOOP;
-- Close the file handle
UTL_FILE.fclose (l_out_file);
END p_write_blob_to_file;
希望,你将设法将其调整到您的情况。
以上是 如何将BLOB图像复制到文件系统 的全部内容, 来源链接: utcz.com/qa/264887.html