Web API 收到一个 pdf 文档,之后它应该将 pdf 文档存储在 Azure 文件共享(存储)中。但是,当执行 ShareFileClient.UploadAsync(stream) 方法时,会引发以下异常:“ResourceNotFound - 指定的资源不存在”。我正在将 pdf 文档上传到文件共享中,这是一个新文件,因此资源肯定不存在。
知道发生了什么吗?这是什么 ResourceNotFound 问题?该代码在另一个 Azure FileShare 中运行,现在我设置了一个新的存储帐户,从那时起问题就开始了。
预期行为
流应上传到以下文件夹中的文件共享:上传/
实际行为(包括异常或堆栈跟踪)
抛出异常 ResourceNotFound - “指定的资源不存在”。
我的代码
public async Task<bool> SaveFileUploaded(string directory, string file, Stream fileStream)
{
// Get a reference to the directory
ShareDirectoryClient directoryClient = _shareClient.GetDirectoryClient(directory);
// Check the client exists
if (directoryClient != null)
{
// Get a reference to a file object
ShareFileClient destFileCLient = directoryClient.GetFileClient(file);
fileStream.Position = 0;
// Start the copy operation
await destFileCLient.UploadAsync(fileStream);
// Ensure that the file was uploaded
if (await destFileCLient.ExistsAsync())
{
return true;
}
else
{
_log.LogError($"File {file} wasn't saved into the uploaded directory : {directory}.", file, directory);
return false;
}
}
else
{
// Directory wasn't initiated.
return false;
}
}
文件共享客户端对象
destFileCLient {Azure.Storage.Files.Shares.ShareFileClient} Azure.Storage.Files.Shares.ShareFileClient AccountName "unistaddocumentssa" string CanGenerateSasUri true bool Name "SC-I60-CAB-ORD-SPE-IT-00015.pdf" string Path "上传/SC-I60-CAB-ORD-SPE-IT-00015.pdf" 字符串 ShareName "unistad-files" 字符串 Uri {https://unistaddocumentssa.file.core.windows.net/unistad-files/uploaded/SC- I60-CAB-ORD-SPE-IT-00015.pdf} System.Uri
ex Message = "指定的资源不存在。\nRequestId:f3cf9c55-a01a-0055-1d43-9755fc000000\nTime:2021-08-22T10:53:37.6138548Z\r\n状态:404(指定的资源不存在。 )\r\n错误代码: ResourceNotFound\r\n\r\n内容:\r\nResourceNotFound
指定的资源不存在。\nRequestId:f3cf9c55-a01a-0055-1d43-9755fc000000\n时间:2021-08-22T10:53:37.6138548Z\r\n\r\n标头:\r\n服务器: Windows-Azure-文件/1.0,Microsoft-HTTPAPI/2.0\r\nx-ms-request-id: f3cf9c55-a01a-0055-1d43-9755fc000000\r\nx-ms-client-request-id: 5d8ed1ff-237d-4edf-a12b- 89bb8aaaa85a\r\nx-ms-version: 2020-08-04\r\nx-ms-error-code: ResourceNotFound\r\nDate: Sun, 22 Aug 2021 10:53:37 GMT\r\nContent-Length: 223\r\nContent-Type: application/xml\r\n" System.Exception {Azure.RequestFailedException} 消息“指定的资源不存在。\nRequestId:f3cf9c55-a01a-0055-1d43-9755fc000000\nTime:2021- 08-22T10:53:37.6138548Z\r\n状态:404(指定的资源不存在。)\r\n错误代码:ResourceNotFound\r\n\r\n内容:\r\nResourceNotFound
指定的资源不存在。\nRequestId:f3cf9c55-a01a-0055-1d43-9755fc000000\n时间:2021-08-22T10:53:37.6138548Z\r\n\r\n标头:\r\n服务器: Windows-Azure-文件/1.0,Microsoft-HTTPAPI/2.0\r\nx-ms-request-id: f3cf9c55-a01a-0055-1d43-9755fc000000\r\nx-ms-client-request-id: 5d8ed1ff-237d-4edf-a12b- 89bb8aaaa85a\r\nx-ms-version: 2020-08-04\r\nx-ms-error-code: ResourceNotFound\r\nDate: Sun, 22 Aug 2021 10:53:37 GMT\r\nContent-Length: 223\r\n内容类型:应用程序/xml\r\n" 字符串
数据 {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal} ErrorCode "ResourceNotFound" string HResult -2146233088 int HelpLink null string InnerException null System.Exception Source "Azure.Storage.Files.Shares" string StackTrace "在 Azure.Storage.Files.Shares.FileRestClient.d__37.MoveNext()\r\n 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) \r\n 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\r\n 在 System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()\r\n at Azure.Storage.Files.Shares.ShareFileClient.<UploadRangeInternal>d__95.MoveNext()\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Azure.Storage.Files.Shares.ShareFileClient.<UploadInternal>d__105.MoveNext()\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.ConfiguredTaskAwaitable
1.ConfiguredTaskAwaiter.GetResult()\r\n 在 Azure.Storage.Files.Shares.ShareFileClient.d__103.MoveNext()\r\n 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n 在系统。 Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)\r\n 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\r\n 在 System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()\r\n at StorageLibrary.Repositories.FileShare.<SaveFileUploaded>d__8.MoveNext() in C:\\Users\\ricar\\OneDrive\\Documentos\\Development\\Projects\\unistad\\Unistad Document Manager Solution\\StorageLibrary\\Repositories\\FileShare.cs:line 264\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()\r\n在 DocumentUploader.Controllers.DocumentUploaderController.d__7.MoveNext() 在 C:\Users\ricar\OneDrive\Documentos\Development\Projects\unistad\Unistad Document Manager Solution\DocumentUploader\Controllers\DocumentUploaderController.cs:line 162" string Status 404 int TargetSite {Void MoveNext()} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo} 静态成员
非公众成员