我有这样一个表格
<form name="" method="post" action="Save" enctype="multipart/form-data">
<div id="dialog" title="Upload files">
<input type="file" id="Image" name="fileUpload" size="23"/>
</div>
<input type="submit" value="Create" />
</form>
我应该如何获取 Controller 中的图像字节?
最佳答案
将以下内容添加到您的 Controller 方法中。
var file = Request.Files["Image"];
if ( file != null )
{
byte[] fileBytes = new byte[file.ContentLength];
file.InputStream.Read( fileBytes, 0, file.ContentLength );
// ... now fileBytes[] is filled with the contents of the file.
}
else
{
// ... error handling here
}
关于c# - 上传图像并获取其字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1934289/