文件存入数据库

        function ajaxFileUpload() {
            var File_box = document.getElementById(‘Download_file‘);
            //var extend = File_box.value.substring(File_box.value.lastIndexOf(".") + 1);
            if (File_box.value == "" || File_box.value == null) {
                alert(‘请先选择文件!‘);
            }
            else {
                $.ajaxFileUpload({
                    url: ‘Download_Manage_Api.ashx?act=file‘,
                    secureuri: false,
                    fileElementId: ‘Download_file‘,
                    dataType: ‘json‘,
                    success: function (data, status) {
                        FileSrc = data[1];
                        alert(data[0] + ‘上传成功‘);
                        $("#FileUploadDiv").css("display", "none");
                        $("#FileLabel").css("display", "block");
                    }
                });
            }
        }

<script src="../Scripts/ajaxfileupload.js" type="text/javascript"></script>
<script src="../Scripts/easyui/jquery.easyui.min.js" type="text/javascript"></script>

api
                //获取前台传来的文件
                HttpFileCollection files = HttpContext.Current.Request.Files;
                Stream st = files[0].InputStream;
                byte[] bytes = new byte[st.Length];
                st.Read(bytes, 0, bytes.Length);
                st.Close();
                string result = "[" + "\"" + BLLPro.InsertFJ(bytes) + "\"]";
                context.Response.Write(result);

dal
        public string InsertFJ(byte[] file)
        {
            string JID = Guid.NewGuid().ToString("N");
            string sql = "insert into jhac_tb_product_fj (JID,PDC_FJ) values (:JID,:PDC_FJ)";
            OracleParameter[] parameters = {
new OracleParameter(":JID", OracleType.VarChar,400),
new OracleParameter(":PDC_FJ", OracleType.Blob)
};
            parameters[0].Value = JID;
            parameters[1].Value = file;
            DbHelperOra.ExecuteSql(sql, parameters);
            return JID;
        }

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。