我使用下面的代码将图像文件从服务器加载到BLOB对象
但将它转换为clob并将其放入json后重新格式化。 我该怎么办?
FUNCTION get_person_image(v_file_name varchar2) RETURN json AS
tmp_blob blob default EMPTY_BLOB();
tmp_bfile bfile := null;
dest_offset integer := 1;
src_offset integer := 1;
v_ret_json json := json();
BEGIN
tmp_bfile := BFILENAME('PICTURES', v_file_name);
DBMS_LOB.OPEN(tmp_bfile, DBMS_LOB.FILE_READONLY);
DBMS_LOB.CREATETEMPORARY(tmp_blob, TRUE);
DBMS_LOB.LOADBLOBFROMFILE(tmp_blob,
tmp_bfile,
DBMS_LOB.LOBMAXSIZE,
dest_offset,
src_offset);
DBMS_LOB.CLOSE(tmp_bfile);
v_ret_json.put('name', v_file_name);
v_ret_json.put('image', blob_to_clob(tmp_blob));
RETURN v_ret_json;
END get_person_image;
FUNCTION blob_to_clob(blob_in IN BLOB) RETURN CLOB AS
v_clob CLOB;
v_varchar VARCHAR2(32767);
v_start PLS_INTEGER := 1;
v_buffer PLS_INTEGER := 32767;
begin
DBMS_LOB.CREATETEMPORARY(v_clob, TRUE);
FOR i IN 1 .. CEIL(DBMS_LOB.GETLENGTH(blob_in) / v_buffer) LOOP
v_varchar := UTL_RAW.CAST_TO_VARCHAR2(DBMS_LOB.SUBSTR(blob_in,
v_buffer,
v_start));
DBMS_LOB.WRITEAPPEND(v_clob, LENGTH(v_varchar), v_varchar);
v_start := v_start + v_buffer;
END LOOP;
RETURN v_clob;
END blob_to_clob;
一旦get_person_image读取图像文件,CLOB包含如下HEX的数据: 00 01 00 00 FF DB 00 84 00 09 06 07 13 13 12 15 13 12 13 15 16 15 15 18 1D 17 17 16 18 17 17 16 18 18 17 18 1A 18 18 17 18 17 18 18 1D 28 20 1A 1A 25 1B 18 17 22 31 21 25 29 2B 2E 2E 2E 17 20 33 38 33 2C 37 28 2D 2E 2B 01 0A 0A 0A 0E 0D 0E 1B 10 10 1B 2D 25 20 25 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2F 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D FF C0 00 11 08 01 0F 00 BA 03 01 22 00 02 11 01 03 11 01 FF C4 00 1C 00 00 01 05 01 01 01 00 00 00 00 00 00 00 00 00 00 05 00 03 04 06 07 02 01 08 FF C4 00 43 10 00 01 02 03 05 05 06 03 07 02 05 02 07 00 00 00 01 02 11 00 03 21 04 05 12 31 41 06 51 61 71 91 22 32 81 A1 B1 F0 13 C1 D1 14 23 42 52 62 82 E1 07 72 15 92 A2 B2 F1 33 C2 16 24 43 63 74 B3 F3 FF C4 00 18 01 00 03 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 01 02 03 04 FF C4 00 21 11 01 01 00 03 01 01 01 01 01 00 03 01 00 00 00 00 00 01 02 11 21 31 41 03 12 22 42 51 81 32 FF DA 00 0C 03 01 00 02 11 03 11 00 3F 00 DB A3 89 B3 00 04 9A 01 1E A9 4D 19 8E DF 6D 62 D4 A3 67 B3 BD 28 A5 0D FB 9F D7 FE 61 5B A3 93 69 3B 5F B7 69 41 32 E4 76 D4 EC 5B 2E 35 1E 9C 6B BA 33 F9 B6 D5 AD 41 53 89 5A F4 4E 89 F9 0F 7C E2 39 93 84 BB E2 51 A5 32 F3 88 76 89 85 CA 52 5B F3 1E 3A 87 FA C4 5B B6 D2 69 2E D7 7B 2A A1 FA 51 23 A6 71 09 53 54 4E A4 EF 67 3E 03 21 E3 0A 4A 10 1A 98 BA 81 EB E6 63 A5 CF 03 26 E6 3D E5 EF 93 93 45 6E CC AA C4 09 FB C5 37 E9 15 5F 5C 93 E0 22 44 A4 24 1F BB 96 90 77 9E D2 FC E2 32 2D 6F 90 61 F9 8D 49 E5 BA 1C 33 30 A5 CD 3A 97 30 C9 39 04 20 E2 99 32 BB 80 0F D6 24 D9 2F 79 45 60 09 20 F1 38 49 26 9A AA 83 C6 2B 33 A6 13 5C 87 31 EB 1D D8 E8 71 00 4B 74 FE 7C 61 06 AB 79 4A 49 97 2F EE A5 8C 75 0A 49 ED 00 CC A0 A3 91 0C 68 74 2D 1D DD 56 F9 72 08 29 99 50 18 B1 A1 6A 54 0A 13 C7 D2 33 4B 55 F4 65 E6 5D 67 47 A2 79 EF 3E F9 C0 5D ED 31 59 13 E8 3A 6B 07 A3 91 F4 75 DB 7B 95 80 42 82 81 19 1A 1C B4 3A C1 8B 35 A9 2B 1D 93 96 63 50 63 06 D9 CB DE 6C 89 92 E6 29 01 68 52 80 51 72 0A 08 EC F6 AA 03 38 53 BB D2 B5 70 0D D6 6D F2 A9 33 5E 59 55 49 39 12 4A 58 66 06 7A D2 1E F4 5F CE DA 58 8F 60 3D C5 7F 4A B4 20 29 2A 0F AB 1D 60 BB C5 22 CD 3D 85 0A 14 04 50 A1 42 80 14 28 50 A0 05 0A 14 28 02 AF B6 D7 DF D9 E4 16 3D B5 F6 53 F3 57 24 FA B4 63 CA. 99 53 9B E6 B5 1F 24 8E 3E F9 17 DB 5B EC CF ..... 当我在PLSQL中打开文本时,它是这样的:
JFIF
在v_ret_json.put之后('图像',blob_to_clob(tmp_blob));它被重新格式化为:
Hex View:
7B 0D 0A 20 20 22 6E 61 6D 65 22 20 3A 20 22 34 31 32 2E 70 6E 67 22 2C 0D 0A 20 20 22 69 6D 61 67 65 22 20 3A 20 22 5C 75 46 46 46 44 5C 75 46 46 46 44 5C 75 46 46 46 44 4A 46 49 46 5C 75 30 30 30 30 5C 75 30 30 30 31 5C 75 30 30 30 31 5C 75 30 30 30 30 5C 75 30 30 30 30 5C 75 30 30 30 31 5C 75 30 30 30 30 5C 75 30 30 30 31 5C 75 30 30 30 30 5C 75 30 30 30 30 5C 75 46 46 46 44 5C 75 46 46 46 44 5C 75 46 46 46 44 5C 75 30 30 30 30 5C 74 5C 75 30 30 30 36 5C 75 30 30 30 37 5C 75 30 30 31 33 5C 75 30 30 31 33 5C 75 30 30 31 32 5C 75 30 30 31 35 5C 75 30 30 31 33 5C 75 30 30 31 32 5C 75 30 30 31 33 5C 75 30 30 31 35 5C 75 30 30 31 36 5C 75 30 30 31 35 5C 75 30 30 31 35 5C 75 30 30 31 38 5C 75 30 30 31 44 5C 75 30 30 31 37 5C 75 30 30 31 37 5C 75 30 30 31 36 5C 75 30 30 31 38 5C 75 30 30 31 37 5C 75 30 30 31 37 5C 75 30 30 31 36 5C 75 30 30 31 38 5C 75 30 30 31 38 5C 75 30 30 31 37 5C 75 30 30 31 38 5C 75 30 30 31 41 5C 75 30 30 31 38 5C 75 30 30 31 38 5C 75 30 30 31 37 5C 75 30 30 31 38 5C 75 30 30 31 37 5C 75 30 30 31 38 5C 75 30 30 31 38 5C 75 30 30 31 44 28 20 5C 75 30 30 31 41 5C 75 30 30 31 41 25 5C 75 30 30 31 42 5C 75 30 30 31 38 5C 75 30 30 31 37 5C 22 31 21 25 29 2B 2E 2E 2E 5C 75 30 30 31 37 20 33 38 33 2C 37 28 2D 2E 2B 5C 75 30 30 30 31 5C 6E 5C 6E 5C 6E 5C 75 30 30 30 45 5C 72 5C 75 30 30 30 45 5C 75 30 30 31 42 5C 75 30 30 31 30 5C 75 30 30 31 30 5C 75 30 30 31 42 2D 25 20 25 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2F 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 2D 5C 75 46 46 46 44 5C 75 46 46 46 44 5C 75 30 30 30 30 5C 75 30 30 31 31 5C 62 5C 75 30 30 30 31 5C 75 30 30 30 46 5C 75 30 30 30 30 5C 75 46 46 46 44 5C 75 30 30 30 33 5C 75 30 30 30 31 5C 22 5C 75 30 30 30 30 5C 75 30 30 30 32 5C 75 30 30 31 31 5C 75 30 30 30 31 5C 75 30 30 30 33 5C 75 30 30 31 31 5C 75 30 30 30 31 5C 75 46 46 46 44 5C 75 46 46 46 44 5C 75 30 30 31 43 5C 75 30 30 30 30 5C 75 30 30 30 30 5C 75 30 30 30 31 5C 75 30 30 30 35 5C 75 30 30 30 31 5C 75 30 30 30 31 5C 75 30 30 30 31 5C 75 30 30 30 30 5C 75 30 30 30 30 5C 75 30 30 30 30 5C 75 30 30 30 30 5C 75 30 30 30 30 5C 75 30 30 30 30 5C 75 30 30 30 30 5C 75 30 30 30 30 5C 75 30 30 30 30 5C 75 30 30 30 30 5C 75 30 30 30 35 5C 75 30 30 30 30 5C 75 30 30 30 33 5C 75 30 30
文字视图:
"名称" :" 412.png", "图像" :" \ uFFFD \ uFFFD \ uFFFDJFIF \ u0000 \ u0001 \ u0001 \ u0000 \ u0000 \ u0001 \ u0000 \ u0001 \ u0000 \ u0000 \ uFFFD \ uFFFD \ uFFFD \ u0000 \ t \ u0006 \ u0007 \ u0013 \ u0013 \ u0012 \ u0015 \ u0013 \ u0012 \ u0013 \ u0015 \ u0016 \ u0015 \ u0015 \ u0018 \ u001D \ u0017 \ u0017 \ u0016 \ u0018 \ u0017 \ u0017 \ u0016 \ u0018 \ u0018 \ u0017 \ u0018 \ u001A \ u0018 \ u0018 \ u0017 \ u0018 \ u0018 \ u0018 \ u001D(\ u001A \ u001A%\ u001 \ u0018 \" 1!%)+ ... \ u0017 383,7( - 。+ \ u0001 \ n \ n \ n \ u000E \ r \ u000E \ u001B \ u0010 \ u0010 \ u001B- %% ------------------ / ----------- -------------------- \ uFFFD \ uFFFD \ u0000的\ u0011 \ b \ U0001 \ u000F \ u0000的\ uFFFD \ U0003 \ U0001 \" \ u0000的\ U0002 \ u0011 \ U0001 \ U0003 \ u0011 \ U0001 \ uFFFD \ uFFFD \ u001C \ u0000的\ u0000的\ U0001 \ u0005 \ U0001 \ U0001 \ U0001 \ u0000的\ u0000的\ u0000的\ u0000的\ u0000的\ u0000的\ u0000的\ u0000的\ u0000的\ u0000的\ u0005 \ u0000的\ U0003 \ U0004 \ u0006 \ u0007 \ U0002 \ U0001 \ b \ uFFFD \ uFFFDC \ u0010 \ u0000的\ U0001 \ U0002 \ U0003 \ u0005 \ u0005 \ u0006 \ U0003 \ u0007 \ U0002 \ u0005 \ U0002 \ u0007 \ u0000的\ u0000的\ u0000的\ U0001 \ U0002 \ u0011 \ u0000的\ U0003 \ U0004 \ u0005 \ u00121A \ u0006Qaq \ uFFFD \"!2 \ uFFFD \ uFFFD \ uFFFD \ uFFFD \ u0014#BRB \ uFFFD \ uFFFD \ u0015 \ uFFFD \ uFFFD \ uFFFD \ uFFFD $ CCT \ uFFFD \ uFFFD \ u0018 \ U0001 \ u0000的\ U0003 \ U0001 \ U0001 \ u0000的符\ u0000 \ u0000的符\ u0000 \ u0000的符\ u0000 \ u0000的符\ u0000 \ u0000的符\ u0000符\ u0000 \ u0000的符\ u0000 \ U0001 \ U0002 \ U0003 \ U0004 \ uFFFD \ uFFFD!\ u0011 \ U0001 \ U0001 \ u0000的\ U0003 \ U0001 \ U0001 \ U0001 \ U0001 \ U0001 \ u0000的\ U0003 \ U0001 \ u0000的符\ u0000 \ u0000的\ u0000的\ u0000的\ U0001 \ U0002 \ u0011 1A \ U0003 \ u0012 \"!?BQ \ uFFFD2 \ uFFFD \ uFFFD \˚F\ U0003 \ U0001 \ u0000的\ U0002 \ u0011 \ U0003 \ u0011 \ u0000的\ u0000的\ u06E3 \ uFFFD \ uFFFD \ u0000的\ U0004 \ uFFFD \ U0001 \ u001E \ uFFFDM \ u0019 \ uFFFD \ uFFFDb \ u0523g \ uFFFD \ uFFFD(\ uFFFD \ r \ uFFFD \ uFFFD \ uFFFDa [\ uFFFD \ uFFFDi; _ \ uFFFDiA2 \ uFFFD \ uFFFD5 \ u001E \ uFFFDk \ uFFFD3 \ uFFFD \ uFFFD \ u056DAS \ uFFFDZ \ uFFFD \ u000F | \ uFFFD \ uFFFD \ uFFFD \ uFFFD2 \ uFFFD \ uFFFD \ uFFFD [\ uFFFD \ uFFFD \ uFFFD \ uFFFD \ uFFFD \。 uFFFD * \ uFFFD \ uFFFDQ#\ uFFFDq \ TSTN \ uFFFD \ uFFFD \ U0003 \ uFFFD \ u0010 \ u001A \ uFFFD \ uFFFD \ uFFFD \ uFFFD \ uFFFD \ uFFFD&安培;!\ uFFFD \ uF4D3En \ u032A