我发布了一张带有图片的表单。 并在我的控制器中接收
var image=Request.Files["hiddenUploadButton"];
现在我想将我的图像转换为Stream。怎么做?
答案 0 :(得分:0)
答案 1 :(得分:0)
if you want to save file try following code snippet
HttpPostedFile file = Request.Files["myFile"];
//check file was submitted
if (file != null && file.ContentLength > 0)
{
string fname = Path.GetFileName(file.FileName);
file.SaveAs(Server.MapPath(Path.Combine("~/App_Data/", fname)));
}
如何转换为流,
HttpPostedFile file = Request.Files["myFile"];
var FileLen = file .ContentLength;
byte[] input = new byte[FileLen];
System.IO.Stream MyStream;
// Initialize the stream.
MyStream = file .InputStream;
// Read the file into the byte array.
MyStream.Read(input, 0, FileLen);