ORA-01460:未实现或不合理的转换请求上传文件

时间:2018-03-15 07:41:52

标签: c# asp.net oracle

以下是在party_images表中上传文件的代码。

protected void upload_Click(object sender, EventArgs e)
{
    try
    {
        using (OracleConnection connection = new OracleConnection(conString))
        {
            connection.Open();
            string filename = Path.GetFileName(FileUpload1.FileName);
            string[] tokenize = filename.Split('.');
            FileUpload1.SaveAs(Server.MapPath("~/files/") + descBox.Text + "." + tokenize[1]);

            string sourceLoc = Server.MapPath("~/files/" + descBox.Text + "." + tokenize[1]);
            FileStream fs = new FileStream(sourceLoc, FileMode.Open, FileAccess.Read);
            byte[] ImageData = new byte[fs.Length];
            fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length));
            fs.Close();
            String block = " BEGIN " +
                           " INSERT INTO party_images(party_id, sr_no, descr, party_image) VALUES ('"+Session["userId"]+"',"+srNo.Text+",'"+descBox.Text+"."+tokenize[1]+"', :1); " +
                           " END; ";
            OracleCommand cmd = new OracleCommand();
            cmd.CommandText = block;
            cmd.Connection = connection;
            cmd.CommandType = CommandType.Text;
            OracleParameter param = cmd.Parameters.Add("blobtodb", OracleDbType.LongRaw);
            param.Direction = ParameterDirection.Input;
            param.Value = ImageData;
            cmd.ExecuteNonQuery();
            descBox.Text = "";
            srNo.Text = "";
        }
    }
    catch (Exception ex) {
            ClientScript.RegisterStartupScript(this.GetType(), "unSuccessMessage", "window.onload = function(){ alert('"+ex.Message+"')};", true);     
    }
    finally
    {
        populateGrid(loadFromDb());
    }
}

表格描述是,

PARTY_ID是VARCHAR2(10)

SR_NO是NUMBER

DESCR是VARCHAR2(50)

PARTY_IMAGE是LONG RAW()

此功能正在上传所有文件,即图像,.docx,.pdf,.sql,但是当我上传任何包含屏幕截图或图片的.docx时,会出现上面的错误。

我尝试了以下链接,

ORA-01460: unimplemented or unreasonable conversion requested

The requested format conversion is not supported.

ORA-01460: unimplemented or unreasonable conversion requested

但我没有任何解决方案。如何在没有此错误的情况下上传任何类型的文件?

1 个答案:

答案 0 :(得分:1)

为什么使用LONG RAW存储二进制对象?这是一个已被弃用超过二十年的数据类型。

如果将$request->input();定义为BLOB(或者可能是BFILE),您会发现它更容易使用。 Find out more