如何在 Blazor 服务器应用程序中上传图像并将图像保存在文件夹中(& 在服务器中)将 url 保存到数据库
how to upload Image in Blazor server app and save the image in the folder (& in the server) save that url to the db
Ive to upload image along with the item and save this images in the
local folder and the server image repository and the image url should
be passed to db. (Have to combine the filepath and the physicalpath )
The code below is not working.
@code{
.
.
.
.
foreach (var file in args.Files)
{
var size = file.FileInfo.Size;
path = "wwwroot\images\" + file.FileInfo.Name;
FileStream filestream = new FileStream(path, FileMode.Create, FileAccess.Write);
file.Stream.WriteTo(filestream);
filestream.Close();
file.Stream.Close();
var pathUrl = path;
}.
.
.
.
arg.Data.ItemImage = path;
}
嗨,
我使用这个 dev express control 来实现这个:
https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxUpload
它需要一些调整,以防您按照示例进行操作,效果很好。
还要确保您在愿意保存文件的文件夹中具有写入权限。
试一试,如果遇到困难请告诉我。
此致,
马蒂亚斯
Ive to upload image along with the item and save this images in the local folder and the server image repository and the image url should be passed to db. (Have to combine the filepath and the physicalpath ) The code below is not working.
@code{
.
.
.
.
foreach (var file in args.Files)
{
var size = file.FileInfo.Size;
path = "wwwroot\images\" + file.FileInfo.Name;
FileStream filestream = new FileStream(path, FileMode.Create, FileAccess.Write);
file.Stream.WriteTo(filestream);
filestream.Close();
file.Stream.Close();
var pathUrl = path;
}.
.
.
.
arg.Data.ItemImage = path;
}
嗨, 我使用这个 dev express control 来实现这个:
https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxUpload
它需要一些调整,以防您按照示例进行操作,效果很好。 还要确保您在愿意保存文件的文件夹中具有写入权限。
试一试,如果遇到困难请告诉我。
此致,
马蒂亚斯