This method is suitable for ASP. NET (C #) + Oracle
The field type in the Oracle table is blob.
# Region Upload File (Binary)
//
Static public byte [] filetobinary (fileupload hifile)
{
Try
{
If (hifile. hasfile)
{
If (isallowedextension (hifile ))
{
// Obtain the size of the uploaded file
Int filelen = hifile. postedfile. contentlength;
Byte [] filedata = new byte [filelen];
// Create an object for accessing the client to upload files
Httppostedfile HP = hifile. postedfile;
// Create a data stream object
Stream sr = hp. inputstream;
// Put the image data in the filedata array object instance. 0 indicates the starting position of the array pointer, and filelen indicates the Ending position of the pointer.
Sr. Read (filedata, 0, filelen );
// String id = "0 ";
// BLL. Picture. addpictures (ID, "name", convert. tostring (filedata), "url", "Description ");
Return filedata; // you only need to save the binary file stream to the database.
}
Else
{
// Response. write ("<SCRIPT upload Ge = 'javascript 'Type = 'text/JavaScript '> alert ('upload files in incorrect format, only jpg and GIF formats are allowed to be uploaded '); </SCRIPT> ");
Return NULL; // "the format of the uploaded file is incorrect. Only jpg and GIF files can be uploaded ";
}
}
Else
{
Return NULL; // "Select Upload File ";
// Response. Write ("<script language = 'javascript 'Type = 'text/JavaScript '> alert ('select upload file'); </SCRIPT> ");
}
}
Catch
{
Return NULL;
}
}
# Endregion