微信小程序上传图片,服务器端接收并保存在当前路径下。在Windows系统上测试可以存上,同样的代码编译后放到Linux上就不行了,返回'An error occurred while updating the entries. See the inner exception for details.'代码如下:
var files = Request.Form.Files;
if (files.Count>0)
{
_wxauthzaService.deletelogs();
sys_log_list log = new sys_log_list();
log.computer_name = "wxxcx";
log.user_name = "test";
var strDateTime = DateTime.Now.ToString("yyyyMMddhhmm"); //取得时间字符串
var strRan = Convert.ToString(new Random().Next(100, 999)); //生成三位随机数
log.list_id = strDateTime + "01";
log.log_string = "接到文件了,数量为" + files.Count;
_wxauthzaService.addlog(log);
//获取当前目录
var s_path = Directory.GetCurrentDirectory() + "/imgs/";
log.list_id = strDateTime + "02";
log.log_string = "目标路径:" + s_path;
_wxauthzaService.addlog(log);
var isexist = Directory.Exists(s_path);
log.list_id = strDateTime + "03";
log.log_string = "路径是否存在:" + isexist;
_wxauthzaService.addlog(log);
if (!Directory.Exists(s_path))
{
Directory.CreateDirectory(s_path);
log.list_id = strDateTime + "04";
log.log_string = "路径不存在,新建路径" ;
_wxauthzaService.addlog(log);
}
try
{
#region 图片文件的条件判断
//文件后缀
var fileExtension = Path.GetExtension(files[0].FileName);
log.list_id = strDateTime + "05";
log.log_string = "获取文件后缀名:"+ fileExtension;
_wxauthzaService.addlog(log);
#endregion
var saveName = strDateTime + strRan + fileExtension;
log.list_id = strDateTime + "06";
log.log_string = "组成图片名:" + saveName;
_wxauthzaService.addlog(log);
//插入图片数据
var item = files[0];
using (FileStream fs = System.IO.File.Create(s_path + saveName))
{
item.CopyTo(fs);
fs.Flush();
}
log.list_id = strDateTime + "07";
log.log_string = "图片写入成功。" ;
_wxauthzaService.addlog(log);
string file_url = "https://www.xxxxxxxx.com/imgs/" + saveName;
log.list_id = strDateTime + "08";
log.log_string = "返回路径:" + file_url;
_wxauthzaService.addlog(log);
return new OkObjectResult(file_url);
}
catch (Exception ex)
{
//这边增加日志,记录错误的原因
//ex.ToString();
log.list_id = strDateTime + "99";
log.log_string = "错误:" + ex.ToString();
_wxauthzaService.addlog(log);
return new OkObjectResult("上传失败");
}
日志结果如下:
_wxauthzaService.addlog(log)方法是向数据库添加日志,执行结果是打印到组成图片名那一步,也没有打印出Exception 。有大佬能提示一下到底是什么问题吗?是获取的路径不对,还是centos system.io?