gpt4 book ai didi

Azure 错误 访问路径被拒绝

转载 作者:行者123 更新时间:2023-12-03 03:06:32 25 4
gpt4 key购买 nike

部署后,我尝试使用将 pdf 文件存储到目录

string biodataPath = Server.MapPath("~/Content/UserImages/");

string fullBiodataPath = Path.Combine(biodataPath, guid.ToString() + extension);

但我收到错误

Could not find a part of the path 'D:\home\site\wwwroot\Content\UserImages\6d8938df-aa4f-40e4-96e3-b2debb6ed992.png'

通过 ftp 连接后,我在 wwwroot 中添加了 Content\UserImages 目录。怎么解决这个问题?

最佳答案

I have added Content\UserImages directory in wwwroot afer connecting through ftp. How to solve this?

如果该目录不存在,您可以尝试创建该目录。

string biodataPath = Server.MapPath("~/Content/UserImages/");

if (!Directory.Exists(biodataPath))
{
DirectoryInfo di = Directory.CreateDirectory(biodataPath);
}

此外,如果可能的话,您可以将静态文件存储在 Azure Blob storage 中.

编辑:我将源图像 SourceImg.png 放在 UserImages 文件夹中,我可以将源文件读入字节数组并将其写入另一个 FileStream。

string biodataPath = Server.MapPath("~/Content/UserImages/");
string pathSource = biodataPath + "SourceImg.png";

//the following code will create new file named 6d8938df-aa4f-40e4-96e3-b2debb6ed992.png
string pathNew = Server.MapPath("~/Content/UserImages/") + "6d8938df-aa4f-40e4-96e3-b2debb6ed992.png";

try
{

using (FileStream fsSource = new FileStream(pathSource,
FileMode.Open, FileAccess.Read))
{
byte[] bytes = new byte[fsSource.Length];
int numBytesToRead = (int)fsSource.Length;
int numBytesRead = 0;
while (numBytesToRead > 0)
{
int n = fsSource.Read(bytes, numBytesRead, numBytesToRead);

if (n == 0)
break;

numBytesRead += n;
numBytesToRead -= n;
}
numBytesToRead = bytes.Length;

// Write the byte array to the new FileStream.
using (FileStream fsNew = new FileStream(pathNew,
FileMode.Create, FileAccess.Write))
{
fsNew.Write(bytes, 0, numBytesToRead);
}
}
}
catch (FileNotFoundException ioEx)
{
Console.WriteLine(ioEx.Message);
}

如果我检查 UserImages 文件夹,我会发现 6d8938df-aa4f-40e4-96e3-b2debb6ed992.png 已创建。

enter image description here

关于Azure 错误 访问路径被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43974701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com