如何实时修改图像并将其保存回服务器?

时间:2018-08-07 10:21:50

标签: asp.net web-applications

我有一个Web应用程序,应该通过读取存储在数据库中的图像路径并将其显示在图像容器上,一次从服务器上的数据库中获取一个图像。当图像显示在客户站点上时,我们具有注释选项以对其进行修改,并且到目前为止,已注释的图像已保存到本地文件夹,然后复制到服务器。我想要的是绕过下载部分,将带注释的图像直接实时地实时存储在服务器上的文件夹中。我们如何实现这一目标?有没有比使用套接字编程更简单的方法?

隐藏代码:

[System.Web.Services.WebMethod(EnableSession = true)]
public static void MoveImages(string imageData)
{
    string fileName = "";
    // get computer name

    string clientMachineName;
    clientMachineName = Dns.GetHostName();
    string computerName = clientMachineName.Split('-').First();

    // get download location

    string pathUser = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
    string sourcePath = Path.Combine(pathUser, "Downloads");


    string pathstring = @"\\servername\shared folder";



    string cls = HttpContext.Current.Session["class"].ToString().Trim();
    string sub = HttpContext.Current.Session["subject"].ToString().Trim();
    string targetPath = System.IO.Path.Combine(pathstring, cls);
    string pathstring1 = targetPath;
    string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
    string destFile = System.IO.Path.Combine(pathstring1, sub);


    if (System.IO.Directory.Exists(sourcePath))
    {

        string[] jpg = System.IO.Directory.GetFiles(sourcePath, "*.jpg");
        string[] png = System.IO.Directory.GetFiles(sourcePath, "*.png");
        string[] files = jpg.Concat(png).ToArray();

        // Copy the files and overwrite destination files if they already exist.
        foreach (string s in files)
        {
            // Use static Path methods to extract only the file name from the path.
            if (s.Length > 0)
            {
                fileName = System.IO.Path.GetFileName(s);
                sourceFile = Path.Combine(sourcePath, fileName);

                destFile = System.IO.Path.Combine(destFile, fileName);
                if (File.Exists(destFile))
                {
                    File.Delete(sourceFile);

                }
                else
                {


                   File.Copy(sourceFile, destFile);

                }
            }
        }
     }

0 个答案:

没有答案