-2
路径值返回根网站路径。但是,我不想在那里存储图像,我想从用户那里获取图像(当他们从本地上传时)。需要上传文件路径才能转换为Byte []
我可以用我的本地路径硬编码字符串,它会工作,但不会在其他环境中工作。我正在运行.net核心1.0。
控制器:
foreach (var file in files)
{
if (file.Length > 0)
{
string path = Path.GetFullPath(model.Filename);
var img = Image.FromFile(Path.Combine(path, file.FileName));
using (var ms = new MemoryStream())
{
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
model.FileData = ms.ToArray();
}
}
}
查看:
<input asp-for="Filename" type="text" id="upload-banner" class="form-control" placeholder="Upload Image" readonly>
<span class="input-group-btn">
<input id="i_file" type="file" name="files" multiple />
<button type="button" class="btn btn-effect-ripple btn-primary">Upload</button>
</span>
谢谢,对不起,我没有正确解释自己,英语不是我的母语。在审查了这个之后,我得到了它的工作,问题是网核已经改变了很多mvc元素。感谢您的回应。 –