如何使用Oracle Forms 6i上传的C#中检索BLOB图像

问题描述

我正尝试使用C#创建一个API,如下所述从Oracle数据库检索图像:

  1. 我正在使用C#.NET Core 2.1
  2. 正在从C#中调用Oracle函数,该函数返回多个字段,其中之一是类型为BLOB的图像字段。
  3. 图像应以Base64格式返回
  4. 图像是使用Oracle 6i表单上传的,但我无权访问该代码
  5. 我可以使用PLsql Developer访问数据库,但是访问BLOB字段时无法正确查看图像(它不显示图像)。我只能看到一些十六进制字符:

enter image description here

  1. 因此,可以使用Oracle Forms 6i检索和显示图像,我也不知道该怎么做,也没有访问源代码的权限。

在我的API解决方案中,我尝试了以下操作:

var lstNews = new List<News>();
var prm = new OracleParameter();

using (OracleConnection con = new OracleConnection(conString))
{
    using (OracleCommand cmd = con.CreateCommand())
    {
        try
        {
            cmd.CommandText = "select * from table(MyPackage.GET_NEWS(:isGeneral))";

            prm = new OracleParameter("isGeneral",OracleDbType.Varchar2);
            prm.Direction = ParameterDirection.Input;
            if (general.Trim() != "")
            {
                prm.Value = general.Trim();
            }
            else {
                prm.Value = System.dbnull.Value;
            }
            cmd.Parameters.Add(prm);
            
            if (con.State == ConnectionState.Closed)
            {
                con.open();
            }

            OracleDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                
                News objNews = new News();
                var count = 0;

                objNews.newsID = Convert.ToInt32(dr[count].ToString());
                objNews.title = dr[++count].ToString();
                objNews.description = dr[++count].ToString();

                // getting blob and converting it to byte then to base64

                OracleBlob blobImage = dr.GetoracleBlob(++count);
                if (!blobImage .IsNull)
                {
                    Byte[] byteArr = new Byte[blobImage .Length];
                    blobImage .Read(byteArr,System.Convert.ToInt32(blobImage .Length));
                    objNews.newsImage = Convert.ToBase64String(byteArr);
                }
                else
                {
                    objNews.newsImage = "";
                }
               
                lstNews.Add(objNews);                           
            }
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
        finally
        {

            if (con.State != ConnectionState.Closed)
            {
                con.Close();
            }
        }
    }
}

请参考this example,您可以在其中找到使用base64解码后返回的图像之一,但无法正常工作(已在codebeautify等在线解码器上进行了检查)

我的代码有问题吗?为什么不起作用,为什么无法正确解码base64图像?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)