[英]Not able to copy file to Azure file share mounted drive when application hosted on IIS in windows VM
I have created windows virtual machine and mounted Azure file share drive as **Z:**.我创建了 windows 虚拟机并将 Azure 文件共享驱动器安装为 **Z:**。 My storage account name is onegbuploadfileshare and file share name is onefileshare .
我的存储帐户名称是onegbuploadfileshare ,文件共享名称是onefileshare 。
I have written a code to write local folder file into Azure file share.我写了一个代码将本地文件夹文件写入 Azure 文件共享。 (Code Ref: https://learn.microsoft.com/en-us/do.net/api/overview/azure/storage.files.shares-readme?view=azure-do.net ).
(代码参考: https://learn.microsoft.com/en-us/do.net/api/overview/azure/storage.files.shares-readme?view=azure-do.net )。 Then hosted the application on IIS in windows VM.
然后将应用程序托管在 windows VM 中的 IIS 上。
But local file not get copied to Azure file share.但是本地文件不会复制到 Azure 文件共享。
My source file path is C:\pubish\Files\1gb.test and destination file path is @"z:\temp\newfile.test" where z drive is mounted drive.我的源文件路径是 C:\pubish\Files\1gb.test 目标文件路径是 @"z:\temp\newfile.test" 其中 z 驱动器是挂载驱动器。
I also programmatically tried with我也以编程方式尝试过
Dos copy command approach processStartInfo.Arguments = @"/C copy /a C:\pubish\Files\1gb.test \onegbuploadfileshare.file.core.windows.net\onefileshare\temp" or /C copy /a C:\pubish\Files\1gb.test Z:\onefileshare\temp\ dos复制命令方式 processStartInfo.Arguments = @"/C copy /a C:\pubish\Files\1gb.test \onegbuploadfileshare.file.core.windows.net\onefileshare\temp" or /C copy /a C:\pubish \Files\1gb.test Z:\onefileshare\temp\
ShareClient approach ShareClient 方法
Az copy approach az复制方法
But not able to save file to file share in any approach.但无法以任何方式将文件保存到文件共享。 Code is working for c:\source to c:\dest file copy.
代码适用于 c:\source 到 c:\dest 文件副本。
Did I miss something on IIS or code?我是不是漏掉了 IIS 或代码? Can anyone provide the solution.
任何人都可以提供解决方案。
I am able to upload files using AZ Copy and by creating a share in Azure by following the below steps.我可以使用 AZ Copy 上传文件,并按照以下步骤在 Azure 中创建共享。
Using Az-copy copied the file to the Azure container.使用 Az-copy 将文件复制到 Azure 容器。
File copied to azure portal.文件复制到azure传送门。
string filePath = @"C:\Temp\sample.txt";
string azurePath = "https://storagerajesh114.blob.core.windows.net/sample/sample.txt";
string key = "Storage Access Key";
string cmd = $"AzCopy /Source:{filePath} /Dest:{azurePath} /DestKey:{key} /S";
using (Process proc = new Process())
{
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.Arguments = $"/C {cmd}";
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.WaitForExit();
Console.WriteLine(proc.StandardOutput.ReadToEnd());
}
Created a share and uploaded a file using the below code.使用以下代码创建共享并上传文件。
string connectionString = "Connection_String";
string shareName = "share";
string dirName = "Test";
string fileName = "sample-file";
string localFilePath = @"C:\Temp\sample.txt";
ShareClient share = new ShareClient(connectionString, shareName);
share.Create();
ShareDirectoryClient directory = share.GetDirectoryClient(dirName);
directory.Create();
ShareFileClient file = directory.GetFileClient(fileName);
using (FileStream stream = File.OpenRead(localFilePath))
{
file.Create(stream.Length);
file.UploadRange(
new HttpRange(0, stream.Length),
stream);
}
You need to use the connection string in the code mentioned in the below screenshots.您需要在以下屏幕截图中提到的代码中使用连接字符串。
Copy the connection string and use it in the code.复制连接字符串并在代码中使用它。
The share folder is created.共享文件夹已创建。
References taken from Azure Storage File Shares client引用自Azure 存储文件共享客户端
and和
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.