1. Define the parameters in the first step
Main Table TableA
public class TableA
{
Public list<tableb> Accidentimgbyte {get; set;}
}
Child table TableB
public class tableb{
Public byte[] Accidentimgflow {get; set;} File stream
Public String Accidentimgname {get; set;} File name
Public String Accidentimgext {get; set;} File format
}
2. Interface
public void Accidentimg_request (TableA tModel) {
String visitimgfile = String. empty;//Picture Path
if (bmmodel.accidentimgbyte! = null)
{
foreach (var item in Tmodel.accidentimgbyte)
{
Visitimgfile + = Attachmenturl (item. Accidentimgflow, item. Accidentimgname, item. Accidentimgext) + ",";
}
if (! String.IsNullOrEmpty (Visitimgfile))
{
Visitimgfile = visitimgfile.substring (0, visitimgfile.length-1);
}
}
}
<summary>
Image processing Methods
</summary>
<param name= "filenameattachment" > File Flow </param>
<param name= "FileName" > File name </param>
<param name= "Fileext" > File format </param>
<returns></returns>
Private String Attachmenturl (byte[] filenameattachment, String fileName, String fileext)
{
String Aurl = system.web.configuration.webconfigurationmanager.appsettings["web. config config upload address"];//server address, Used to return the server picture address combination, such as: http://x.x.x/
Try
{
Write directory
String AttachmentPath = system.web.configuration.webconfigurationmanager.appsettings["web. config config upload address"] + fileName + Fileext;
File.writeallbytes (AttachmentPath, filenameattachment);
Aurl = Aurl + fileName + fileext;//stitching return address such as: http://x.x.x/test 1.jpg
}
catch (Exception ex)
{
HX.BPM.Common.LogWriter.Write ("Log", "Baggagemonitoradd_request", "Baggage monitoring process Initiation handling Exception", ex. Message);
Aurl = null;
}
return aurl;
}
3. Front-end (external) call
private void Button1_Click (object sender, EventArgs e)
{
TableA ta=new TableA ();
Ta. accidentimgbyte = new attmodel[2];//definition length
byte[] Aimag = filecontent (@ "Local picture path");
Ta. Accidentimgbyte[0]=new TableB () {
Accidentimgflow = Aimag,
Accidentimgname = "Test 1",
accidentimgext= ". jpg"
};
Aimag = filecontent (@ "Local picture path");
Ta. ACCIDENTIMGBYTE[1] = new TableB ()
{
Accidentimgflow = Aimag,
Accidentimgname = "Test 2",
Accidentimgext = ". jpg"
};
var result = Accidentimg_request (TA);
}
Convert files into streams
private static byte[] Filecontent (string fileName)
{
FileStream fs = new FileStream (FileName, FileMode.Open, FileAccess.Read);
Try
{
byte[] Buffur = new Byte[fs. Length];
Fs. Read (Buffur, 0, (int) fs. Length);
return Buffur;
}
catch (Exception ex)
{
return null;
}
Finally
{
if (fs! = NULL)
Fs. Close ();
}
}
C # file stream upload picture