C# 从azure功能应用程序将文件上载到azure文件共享
我有一个功能应用程序和azure文件共享。我想使用url将文件从internet上载到我的azure文件共享存储C# 从azure功能应用程序将文件上载到azure文件共享,c#,azure-storage,azure-function-app,azure-files,C#,Azure Storage,Azure Function App,Azure Files,我有一个功能应用程序和azure文件共享。我想使用url将文件从internet上载到我的azure文件共享存储 private ShareFileClient GetShareFile(string filePath) { string connectionString = "My connection string"; return new ShareFileClient(connectionString, "tem
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));
但这段代码没有按预期工作。这是一个“未经授权”的错误
请求ID:000db1ff-801a-000a-0602-b24449000000
时间:2020-11-03T16:58:36.5697281Z
状态:401(未经授权)
错误代码:无法验证CopySource”。非常感谢您提供的任何帮助一个简单的代码:
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();
以上代码在我这方面运行良好,您只需先将文件转换为流。“此代码未按预期工作”-此语句没有特别的帮助。请更具体地说明如何知道它没有“按预期”工作,包括运行此代码时发生的情况、预期发生的情况以及这两种结果的具体差异。另请参见:首先,您应该在控制台项目中测试代码,看看它是否有效。此外,请提供更多可用于重新编程/调试问题的代码。最后,
DownloadUrl
是否公开而不需要验证?