将dropzone保存到数据库而不是保存到文件中

时间:2018-09-24 10:51:02

标签: c# window

我使用dropzonejs可以将图像保存在文件夹中,是否有可能将其保存为asp图像,这样我就可以将其插入数据库了!

这是我的httprequest “ context.Response.ContentType =” image / plain“;

        string dirFullPath = HttpContext.Current.Server.MapPath("~/image/");
        string[] files;
        int numFiles;
        files = System.IO.Directory.GetFiles(dirFullPath);
        numFiles = files.Length;
        numFiles = numFiles + 1;

        string str_image = "";

        foreach (string s in context.Request.Files)
        {
            HttpPostedFile file = context.Request.Files[s];
            string fileName = file.FileName;
            string fileExtension = file.ContentType;

            if (!string.IsNullOrEmpty(fileName))
            {
                fileExtension = Path.GetExtension(fileName);
                str_image = numFiles.ToString() + fileExtension;
                string pathToSave = HttpContext.Current.Server.MapPath("~/image/") + str_image;
                file.SaveAs(pathToSave);
            }
        }

        context.Response.Write(str_image);

0 个答案:

没有答案