javascript 无法使用ORDS REST API将BLOB内容从Oracle APEX传输到另一个数据库

lx0bsm1f  于 9个月前  发布在  Java
关注(0)|答案(1)|浏览(62)

当用户使用Oracle APEX中的“文件浏览”项选择图像/文档时,需要通过ORDS REST API将该图像/文档传输到远程DB。ORDS POST API是在remove DB上创建的,它接受类似内容的参数,类型等。并插入详细信息到数据库。它是工作查找,但不知何故BLOB(图像/文档)在远程数据库中损坏。以下是在Oracle APEX页面中创建的项目详细信息-
x1c 0d1x的数据
使用此项目上传的图像/文档将进入APEX临时表(apex_application_temp_files)。现在,当用户单击“上传”时,以下JavaScript将被执行-

//alert('here');
var base64Image = "";
var fileName = $v('P28_NEW');

var getImageDetails = async function() {
    //alert('inside get image details func');
    return apex.server.process(
        "GET_IMAGE_DETAILS", {
            x01: fileName
        }, {
            async: false,
            dataType: "json",
            success: function(pData) {
                console.log('success');
                console.log('requestBody:'+JSON.stringify(pData));
            },
            error: function(request, status, error) {
                alert("Error1:" + error);
            },
        }
    );
};

async function mainFunction() {
    try {
        var callFunction1 = await getImageDetails();

        var apiUrl = '...../ords/..../..../image/api?TITLE=test&FILENAME=test&SUBMITTED_BY=ssss&MIMETYPE=application/pdf';
        var imageContent = callFunction1.image;
        var imageType = callFunction1.mimetype; 
        //console.log('requestBody:'+JSON.stringify(callFunction1));
       
        fetch(apiUrl, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: imageContent
            })
            .then(function(response) {
                if (response.ok) {
                    console.log('successful');
                } else {
                    console.error('failed');
                }
            })
            .catch(function(error) {
                console.error('Error:', error);
            });

    } catch (e) {
        console.error(e);
    }
}

mainFunction();

字符串
此JavaScript函数调用一个AJAX进程来获取上传的图像/文档的内容-

DECLARE
  l_image       CLOB;
  l_mime_type   VARCHAR2 (255);
  l_imag1e varchar2(500):=  APEX_APPLICATION.g_x01;
BEGIN
  SELECT blob_content, mime_type
                  INTO l_image, l_mime_type
                  FROM apex_application_temp_files
                 WHERE name = l_imag1e; 
    
   -- Return the values using apex_json package
    apex_json.open_object;
    apex_json.write('image', l_image);
    apex_json.write('mimetype', l_mime_type);
    apex_json.close_object; 
    exception   
     when others then
        apex_json.open_object; 
        apex_json.write('message', sqlerrm);
        apex_json.close_object; 
        --htp.p(sqlerrm);
END;


ORDS REST API,在远程DB上创建。它使用“:body”参数提取内容。


xytpbqjk

xytpbqjk1#

在PL/SQL代码块中,您获取列blob_content并将其放入l_image,一个clob变量。
你试过通过apex_web_service.blob2clobbase64转换blob_content吗?

DECLARE
  l_image       CLOB;
  l_mime_type   VARCHAR2 (255);
  l_imag1e varchar2(500):=  APEX_APPLICATION.g_x01;
BEGIN
  SELECT apex_web_service.blob2clobbase64(blob_content), mime_type
                  INTO l_image, l_mime_type
                  FROM apex_application_temp_files
                 WHERE name = l_imag1e; 
    
   -- Return the values using apex_json package
    apex_json.open_object;
    apex_json.write('image', l_image);
    apex_json.write('mimetype', l_mime_type);
    apex_json.close_object; 
    exception   
     when others then
        apex_json.open_object; 
        apex_json.write('message', sqlerrm);
        apex_json.close_object; 
        --htp.p(sqlerrm);
END;

字符串
当然,您需要在目标DB中将其转换回blob,例如使用APEX_WEB_SERVICE.CLOBBASE642BLOB

相关问题