我有一个ASP.NET MVC 4应用程序,想要部署到Windows Azure。该应用程序的一部分涉及上传图片。当图片上传完成后,我想把它存储在位于 /pictures/uploaded
的目录中。
我的问题是,在托管在Windows Azure上的应用程序中如何将图片上传到相对路径?到目前为止,我的应用程序已经托管在虚拟机上了。我能够通过使用以下方式完成上述操作:
string path = ConfigurationManager.AppSettings["rootWebDirectory"] + "/pictures/uploaded;
// Get the file path
if (Directory.Exists(path) == false)
Directory.CreateDirectory(path);
string filePath = path + "/uploaded" + DateTime.UtcNow.Milliseconds + ".png";
filePath = filePath.Replace("/", "\\").Replace("\\\\", "\\");
// Write the picture to the file system
byte[] bytes = GetPictureBytes();
using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
{
fileStream.Write(bytes, 0, bytes.Length);
fileStream.Flush();
fileStream.Close();
}
目前,ConfigurationManager.AppSettings["rootWebDirectory"]
指向一个绝对路径,我相信这是我的问题所在。我无法弄清如何将所有内容切换为相对路径。
谢谢!