我正在尝试在远程 SQl 服务器中上传新帖子,一切正常,但是当我在上传中选择照片时,它说“处理您的请求时发生错误”,这在本地主机服务器上效果很好,但在远程服务器上则不然
公共(public)异步任务 NewPost([Bind("Id,Title,PhotoUrl,Category,Description,")]Post post) {
var files = HttpContext.Request.Form.Files;
foreach (var Image in files)
{
if (Image != null && Image.Length > 0)
{
var file = Image;
var uploads = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/postimages");
if (file.Length > 0)
{
var fileName = ContentDispositionHeaderValue.Parse
(file.ContentDisposition).FileName.Trim('"');
System.Console.WriteLine(fileName);
using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create))
{
await file.CopyToAsync(fileStream);
post.PhotoUrl = file.FileName;
}
}
}
}
post.Author = _user.GetUserName(HttpContext.User);
_context.Posts.Add(post);
await _context.SaveChangesAsync();
return RedirectToAction("Index", "Admin");
}
它在本地服务器上完美运行,
最佳答案
该问题似乎是存储权限问题。它在本地主机中工作正常,并且仅在服务器中显示错误。此外,在您的评论中,您提到这是在共享托管解决方案中。在 Windows 共享主机中,您必须专门为 IIS 用户授予特定文件夹的权限。这可以在您的托管提供商的网站上完成(您可能有一个控制台,例如parallels)。
关于mysql - 向远程 MySql 服务器添加数据时发生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56499210/