我已经知道如何将图片存储在数据库中,只需在我的表中使用 bytea
类型。
而且,我已经可以通过我的 .net Core 项目中的代码将图像保存到数据库中。我只是通过 url
获取图像并像这样保存:
using (HttpResponseMessage res = await client.GetAsync(photo_url))
using (HttpContent content = res.Content) {
byte[] imageByte = await content.ReadAsByteArrayAsync();
using (NpgsqlConnection conn = new NpgsqlConnection("ConnectionString")) {
conn.Open();
using (NpgsqlTransaction tran = conn.BeginTransaction())
using (NpgsqlCommand cmd = new NpgsqlCommand("Photo_Save", conn)) {
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("photo", NpgsqlTypes.NpgsqlDbType.Bytea, imageByte);
cmd.ExecuteScalar();
tran.Commit();
}
}
它运行良好
但我需要将来自我的电脑的图像保存到表中
是否有一种方法可以将图像上传到数据库,而不需要在主机上或任何其他项目中编写代码,只需使用本地图片和连接到Postges DB?