protected void ExportToImage(object sender, EventArgs e)
{
string base64 = Request.Form[hfImageData.UniqueID].Split(',')[1];
byte[] bytes = Convert.FromBase64String(base64);
File.Copy(bytes.ToString()+".jpg", "\\\\192.168.2.9\\Web");
}我从jquery获得的hfImageData数据,在用户完成绘图之后,我将把卷积转换成base64。然后调用c#函数将base64转换成jpg图像文件到服务器,并存储到DB中。
当我触发onclick按钮im获取错误时,:System.IO.FileNotFoundException:找不到文件‘System.Byte[]..jpg’.
知道为什么吗?
发布于 2016-11-15 03:46:55
在这一行File.Copy(bytes.ToString()+".jpg", "\\\\192.168.2.9\\Web");中,您实际上是在尝试转换字节数组的内容并将其用作图像名称,但这实际上不会创建文件。
bytes.ToString()只是返回对象的类型,而不是内容。所以你才会看到System.Byte[].jpg
解决这个问题的方法是改变您的功能:
protected void ExportToImage(object sender, EventArgs e)
{
string base64 = Request.Form[hfImageData.UniqueID].Split(',')[1];
byte[] bytes = Convert.FromBase64String(base64);
//write the bytes to file:
File.WriteAllBytes(@"c:\temp\somefile.jpg", bytes); //write to a temp location.
File.Copy(@"c:\temp\somefile.jpg", @"\\192.168.2.9\Web");//here we grab the file and copy it.
//EDIT: based on permissions you might be able to write directly to the share instead of a temp folder first.
}发布于 2016-11-15 03:42:17
bytes.ToString()不返回任何有意义的内容。
您的字节不是文件;您不能复制它们。
相反,调用File.WriteAllBytes()将它们直接写入一个新文件。
https://stackoverflow.com/questions/40601591
复制相似问题