【发布时间】:2018-12-24 06:06:29
【问题描述】:
我已经知道如何在数据库中存储图像,只需在我的表中输入bytea
我已经可以通过我的项目 .net Core 中的代码将图像保存到 DB,我刚刚通过 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连接?
【问题讨论】:
-
你见过stackoverflow.com/questions/22288898/…>吗?
-
@Ravi 你看到这个问题被问到了吗? :)
-
是的,我刚才看到了。如果我在 7 月看到这个,我会在 2018 年 7 月 16 日回答。抱歉回答晚了。我以前没见过这个。抱歉。
标签: postgresql bytea