简体   繁体   English

将文件从 azure 函数应用上传到 azure 文件共享

[英]Uploading file to azure file share from azure function app

I have a function app and azure fileshare.我有一个函数应用程序和 azure 文件共享。 I want to upload a file from internet using the url to my azure file share storage.我想使用 url 从 Internet 上传文件到我的 azure 文件共享存储。

  private ShareFileClient GetShareFile(string filePath)
    {
        string connectionString = "My connection string";

        return new ShareFileClient(connectionString, "temp", filePath);
    }

         ShareFileClient destFile = GetShareFile(filePath);

            // Start the copy operation
            await destFile.StartCopyAsync(new Uri(DownloadUrl));

But this code is not working as expected.但是这段代码没有按预期工作。 It is throwing error "Unauthorized RequestId:000db1ff-801a-000a-0602-b24449000000 Time:2020-11-03T16:58:36.5697281Z Status: 401 (Unauthorized) ErrorCode: CannotVerifyCopySource" .它抛出错误“未经授权的 RequestId:000db1ff-801a-000a-0602-b24449000000 时间:2020-11-03T16:58:36.5697281Z 状态:401(未经授权)错误代码:CannotVerifyCopySource” Any helps will be highly appreciated任何帮助将不胜感激

A simple code to write and read:一个简单的代码来编写和阅读:

    string con_str = "DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxxxxx;EndpointSuffix=core.windows.net";
    string sharename = "test";
    string filename = "test.txt";
    string directoryname = "testdirectory";

    ShareServiceClient shareserviceclient = new ShareServiceClient(con_str);
    ShareClient shareclient = shareserviceclient.GetShareClient(sharename);
    ShareDirectoryClient sharedirectoryclient = shareclient.GetDirectoryClient(directoryname);

    //write data.
    ShareFileClient sharefileclient_in = sharedirectoryclient.CreateFile(filename,1000);
    string filecontent_in = "This is the content of the file.";
    byte[] byteArray = Encoding.UTF8.GetBytes(filecontent_in);
    MemoryStream stream1 = new MemoryStream(byteArray);
    stream1.Position = 0;
    sharefileclient_in.Upload(stream1);

    //read data.
    ShareFileClient sharefileclient_out = sharedirectoryclient.GetFileClient(filename);
    Stream stream2 = sharefileclient_out.Download().Value.Content;
    StreamReader reader = new StreamReader(stream2);
    string filecontent_out = reader.ReadToEnd();

Above code works fine on my side, you just need to convert file to stream first.上面的代码在我这边工作正常,你只需要先将文件转换为流。

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

相关问题 Azure 应用服务 Windows 容器 - 使用装载存储错误将文件上传到文件共享 - Azure app service windows container - Uploading file to File share using mount storage error 上传文件 IFormFile 到 Azure C# function - Uploading file IFormFile to Azure C# function 当文件上传到 azure 文件共享时,如何添加触发器以将文件从 azure 文件共享移动到 azure blob? - How to add trigger to move file to azure blob from azure file share when a file uploaded to azure file share? 使用UploadFromFile将文件上传到Azure - Uploading a file to Azure using UploadFromFile 快速将文件上传到Azure Blob - Uploading a file to Azure Blob on the fly 创建文件为 ZF7B44CFFAFD5C52223D5498196C8A2E7BZ 并上传到 Azure - Creating a file as a stream and uploading to Azure 将文件从OneDrive上载到Azure-文件内容问题 - Uploading a File from OneDrive to Azure - issues with file content 使用功能app将文件从Sftp移到Azure容器 - Move the file from Sftp to the Azure container using function app Azure WebJobs与存储文件共享 - Azure WebJobs with Storage File Share 如何从Azure文件共享下载文件结尾 - How do I download the end of a file from azure file share
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM