Retrieve image from Oracle DB

后端 未结 1 1939
面向向阳花
面向向阳花 2021-01-26 08:40

So, i am using a web api to retrieve a image!! But, at the DB the image is a LongRaw. Im seeing at the google that i need to use the OracleDbType.Blob But, when i try to use th

相关标签:
1条回答
  • 2021-01-26 08:47

    I'm not sure what lretorno.Load(...) is doing to read the data, but this sudo code sample using a select statement might help you... I've always had to specifically get the blob and read it out to get the bytes in the past.

    Example for retrieving a LONG RAW DataType

    var imgCmd = new OracleCommand("SELECT photo FROM photos WHERE photo_id = 1", _con);
    imgCmd.InitialLONGFetchSize = -1; // Retrieve the entire image during select instead of possible two round trips to DB
    var reader = imgCmd.ExecuteReader();
    if (reader.Read()) {
        // Fetch the LONG RAW
        OracleBinary imgBinary = reader.GetOracleBinary(0);
        // Get the bytes from the binary obj
        byte[] imgBytes = imgBinary.IsNull ? null : imgBinary.Value;
    }
    reader.Close();
    

    Example for retrieving a BLOB DataType

    var imgCmd = new OracleCommand("SELECT photo FROM photos WHERE photo_id = 1", _con);
    var reader = imgCmd.ExecuteReader();
    if (reader.Read()) {
        // Fetch the blob
        OracleBlob imgBlob = reader.GetOracleBlob(0);
        // Create byte array to read the blob into
        byte[] imgBytes = new byte[imgBlob.Length];
        // Read the blob into the byte array
        imgBlob.Read(imgBytes, 0, imgBlob.Length);
    }
    reader.Close();
    
    0 讨论(0)
提交回复
热议问题