繁体   English   中英

当应用程序托管在 windows VM 中的 IIS 上时,无法将文件复制到 Azure 文件共享安装的驱动器

[英]Not able to copy file to Azure file share mounted drive when application hosted on IIS in windows VM

我创建了 windows 虚拟机并将 Azure 文件共享驱动器安装为 **Z:**。 我的存储帐户名称是onegbuploadfileshare ,文件共享名称是onefileshare

我写了一个代码将本地文件夹文件写入 Azure 文件共享。 (代码参考: https://learn.microsoft.com/en-us/do.net/api/overview/azure/storage.files.shares-readme?view=azure-do.net )。 然后将应用程序托管在 windows VM 中的 IIS 上。

但是本地文件不会复制到 Azure 文件共享。

我的源文件路径是 C:\pubish\Files\1gb.test 目标文件路径是 @"z:\temp\newfile.test" 其中 z 驱动器是挂载驱动器。

我也以编程方式尝试过

  1. 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\

  2. ShareClient 方法

  3. az复制方法

但无法以任何方式将文件保存到文件共享。 代码适用于 c:\source 到 c:\dest 文件副本。

我是不是漏掉了 IIS 或代码? 任何人都可以提供解决方案。

我可以使用 AZ Copy 上传文件,并按照以下步骤在 Azure 中创建共享。

使用 Az-copy 将文件复制到 Azure 容器。

在此处输入图像描述

文件复制到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());
            }
       

使用以下代码创建共享并上传文件。


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);
            }

您需要在以下屏幕截图中提到的代码中使用连接字符串。

在此处输入图像描述

在此处输入图像描述

复制连接字符串并在代码中使用它。

在此处输入图像描述

共享文件夹已创建。

在此处输入图像描述

在此处输入图像描述

引用自Azure 存储文件共享客户端

复制

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM