我正在使用Web API。我在Visual Studio中配置了AWS Elastic Beanstalk,以便将代码部署到我的服务器。昨天我陷入了一个问题,将图像保存到服务器上的文件夹中(作为应用程序的wwwroot兄弟)。所以我为了测试的目的,在下面给出的代码中做了
string subpath = "~/JukesterContent/Images/User";
JukesterContent / User是我想要保存图像的文件夹,它与wwwroot一起出现在C / inetpub中。当我部署代码时,在部署时它创建了另一个名为" JukesterWebAPI_deploy"的文件夹。部署包内部(我看到使用RDC),它包含我上传的图像。我现在不想要这个。下面的代码是恢复的代码,清理后的解决方案,重建它然后部署但它仍然创建文件夹。如何更新这个东西?
`byte[] contents = Convert.FromBase64String(imageString.Trim('\0'));
string subpath = ConfigurationManager.AppSettings["UserImagesFolder"];
if (!string.IsNullOrEmpty(subpath))
{
bool exists = Directory.Exists(HttpContext.Current.Server.MapPath(subpath));
if (!exists)
{
Directory.CreateDirectory(HttpContext.Current.Server.MapPath(subpath));
}
string fileName = "Image-" + userId + ".png";
var savePath = HttpContext.Current.Server.MapPath(subpath);
var imagePath = Path.Combine(savePath, Path.GetFileName(fileName));
if (File.Exists(imagePath))
{
//if a file exists against this user, then delete it, this will be used in update case
File.Delete(imagePath);
}
using (var imageFile = new FileStream(imagePath, FileMode.Create))
{
imageFile.Write(contents, 0, contents.Length);
}
return fileName;
}`