Unknown Location when trying to upload to Sharepoint using Graph API

Informática Guerola 1 Reputation point
2021-10-29T08:23:38.523+00:00

I'm facing with an error when uploading files to sharepoint,

An unhandled exception occurred while processing the request. AggregateException: One or more errors occurred. Unknown location TaskCanceledException: Upload failed too many times. See InnerException for list of exceptions that occured. Microsoft.Graph.LargeFileUploadTask.UploadAsync(IProgress progress, int maxTries)

This is the code used:

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


            }

But we see the

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

On the sharepoint folder where we're trying to store, this means that some temporaly file has been created on the folder, but not the final file

Any clue about this problem??

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,998 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,283 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,269 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 38,646 Reputation points Microsoft Vendor
    2021-11-01T07:42:17.373+00:00

    Hi @Informática Guerola ,
    The Microsoft Graph SDKs support resuming in-progress uploads. If your application encounters a connection interruption or a 5.x.x HTTP status during upload, you can resume the upload.

    fileUploadTask.ResumeAsync(progress);  
    

    145318-image.png
    Please refer to the following document
    https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0&preserve-view=true#resuming-an-in-progress-upload


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.