app客户端提交表单,附加图片,asp.net后台接收代码:
Stream sr = Request.InputStream;
byte[] buffer = new byte[4096];
int bytesRead = 0;
//将当前数据流写入服务器端文件夹upload下
const string savePath = "/upload/"; //目标图片路径
string dirPath = Server.MapPath(savePath);
string picName = DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";
string path = dirPath + picName;
string imgPath = "/upload/" + picName;
using (FileStream fs = File.Create(path, 4096))
{
while ((bytesRead = sr.Read(buffer, 0, buffer.Length)) > 0)
{
//向文件中写信息
fs.Write(buffer, 0, bytesRead);
}
}
Request.Files[0].SaveAs(path); //保存上载的内容,如果没有这段代码,服务器讲接收不到图片