gpt4 book ai didi

c# - 上传图像并获取其字节

转载 作者:太空宇宙 更新时间:2023-11-03 17:19:06 25 4
gpt4 key购买 nike

我有这样一个表格

<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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com