在C#WinForm App中将图像存储在服务器硬盘上的最佳方法

问题描述 投票:-1回答:1

就我而言,直接在SQL DB中存储图像并不是最好的方法。特别是当它们有很多具有巨大空间的时候。专家声称,最好只将图像名称插入数据库并将图像存储在H盘上。

所以,我写了一些如下所示的代码,用于将图像保存在用户计算机的H盘上:

private void btnSave_Click(object sender, EventArgs e)
{
    string imageName = Guid.NewGuid().ToString() + Path.GetExtension(PicBoxCustomer.ImageLocation);
    string path = Application.StartupPath + "/Images/";

    if (!Directory.Exists(path))
    {
        Directory.CreateDirectory(path);
    }

    PicBoxCustomer.Image.Save(path + imageName);

    Customers customers = new Customers()
            {
                Address = txtAddress.Text,
                Email = txtEmail.Text,
                FullName = txtName.Text,
                Mobile = txtMobile.Text,
                CustomerImage = imageName
            };

   if (customerId == 0)
   {
       db.CustomerRepository.InsertCustomer(customers);
   }
   else
   {
       customers.CustomerID = customerId;
       db.CustomerRepository.UpdateCustomer(customers);
   }

   db.Save();
}

这适用于单个用户,但在现实世界中,我的公司有大约1300名人员(用户),我必须找到一种方法来保存服务器硬盘上所有用户PC的图像(不是每个用户的计算机上)分开,具有向所有用户显示所有图像的能力)。

我有两个问题:

  1. 我应该如何通过内联网将图像从用户的PC传输(上传)到服务器?
  2. 如何更改上述代码以将图像保存在服务器硬盘而不是用户的计算机上?

我正在使用具有存储库设计模式的LINQ技术(DataContext)。

你能帮帮我吗?

c# winforms linq client-server
1个回答
1
投票

您在本主题中提出了多个问题,并且没有说明您的尝试和失败。

对于线索,您应该编写向客户端提供API的Web服务,以将图像上传到服务器并在服务器本地存储主题,搜索WCF或WebAPI以在C#中实现Web服务。

  • 由于随着时间的推移增加了数据库的大小,因此不要将图像的内容存储在数据库中。
© www.soinside.com 2019 - 2024. All rights reserved.