首页 > 解决方案 > 位置未知,将文件上传到 Sharepoint 时使用 Microsoft Graph API 时出现问题

问题描述

将文件上传到共享点时遇到错误,

处理请求时发生未处理的异常。AggregateException:发生一个或多个错误。未知位置 TaskCanceledException:上传失败太多次。有关发生的异常列表,请参阅 InnerException。Microsoft.Graph.LargeFileUploadTask.UploadAsync(IProgress 进度,int maxTries)

  using (FileStream fileStream = System.IO.File.OpenRead(filePath))
                {


                    // Use properties to specify the conflict behavior
                    // in this case, replace
                    var uploadProps = new DriveItemUploadableProperties
                    {
                        ODataType = null,
                        AdditionalData = new Dictionary<string, object>
                            {
                                { "@microsoft.graph.conflictBehavior", "replace" }
                            }
                    };


                    var uploadSession = await _graphServiceClient.Drives["b!G_sdavHlaEmqc9oVvd2b-WJ1ylhoxrtPt9v6xJPy1RQH5vGZK44uQau0-P9QCo5r"]
                       .Root
                       .ItemWithPath(file.FileName)
                       .CreateUploadSession(uploadProps)
                       .Request()
                       .PostAsync();

                    // Max slice size must be a multiple of 320 KiB
                    int maxSliceSize = 320 * 1024;
                    var fileUploadTask =
                        new LargeFileUploadTask<DriveItem>(uploadSession, fileStream, maxSliceSize);

                 

                    // Create a callback that is invoked after each slice is uploaded
                    IProgress<long> progress = new Progress<long>(prog => {
                        Console.WriteLine($"Uploaded {prog} bytes of {fileStream.Length} bytes");
                    });

                    try
                    {
                        // Upload the file
                         
                       var uploadResult = await fileUploadTask.UploadAsync(progress);

                        if (uploadResult.UploadSucceeded)
                        {
                            // The ItemResponse object in the result represents the
                            // created item.
                            Console.WriteLine($"Upload complete, item ID: {uploadResult.ItemResponse.Id}");
                        }
                        else
                        {
                            Console.WriteLine("Upload failed");
                        }
                    }
                    catch (ServiceException ex)
                    {
                        Console.WriteLine($"Error uploading: {ex.ToString()}");
                    }

                  
                }

但我们看到

 Creaste ~tmp95_Manipulador de Alimentos GUERO...pdf en ex3 Hace un minuto

在我们尝试存储的共享点文件夹上,这意味着在该文件夹上创建了一些临时文件,但不是最终文件

关于这个问题的任何线索?

标签: c#sharepointmicrosoft-graph-api

解决方案


推荐阅读