0

I'm trying to upload a large file (> 4 MB) to a Sharepoint drive using VB.Net and the Microsoft Graph API. For testing purposes I aim for the root of the drive. Later on I will specify a subfolder. This is the code I use:

Public Shared Async Function UploadToFolder(ByVal driveId As String) As Task(Of DriveItem)
        Dim resultDriveItem As DriveItem = Nothing
        Try
            Using fileStream As New IO.FileStream(fileLocation, IO.FileMode.Open, IO.FileAccess.Read)
                Dim uploadSession As UploadSession = Await GraphClient.Drives(driveId).Root.ItemWithPath("test.pdf").CreateUploadSession().Request().PostAsync()
                Dim maxSlice As Integer = 320 * 1024
                Dim largeFileUpload As New LargeFileUploadTask(Of DriveItem)(uploadSession, fileStream, maxSlice)
                Dim uploadResult As UploadResult(Of DriveItem) = Await largeFileUpload.UploadAsync() 'error occurs here
                resultDriveItem = uploadResult.ItemResponse
            End Using
        Catch ex As Exception
            Stop
        End Try
        Return resultDriveItem
    End Function

Unfortunately an error occurs at Await largeFileUpload.UploadAsync(). When I look at the error message, it doesn't make much sense:

Code: generalException
Message: An error occurred sending the request.

On top of that the stacktrace doesn't help me any further either.

   bij Microsoft.Graph.SimpleHttpProvider.<SendRequestAsync>d__13.MoveNext()
--- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
   bij System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   bij System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   bij Microsoft.Graph.SimpleHttpProvider.<SendAsync>d__10.MoveNext()
--- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
   bij System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   bij System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   bij Microsoft.Graph.UploadSliceRequest`1.<SendRequestAsync>d__18.MoveNext()
--- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
   bij System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   bij System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   bij Microsoft.Graph.UploadSliceRequest`1.<PutAsync>d__17.MoveNext()
--- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
   bij System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   bij System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   bij Microsoft.Graph.LargeFileUploadTask`1.<UploadSliceAsync>d__14.MoveNext()
--- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
   bij System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   bij System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   bij Microsoft.Graph.LargeFileUploadTask`1.<UploadAsync>d__16.MoveNext()
--- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
   bij System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   bij System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   bij Office365.Office365.VB$StateMachine_12_UploadToFolder.MoveNext() in C:\Note-books\Projects 2013\SharedTools\Tools\Office365\Office365.vb:regel 294

The thing is that I can upload a smaller file (with PutAsync) or do other stuff (create folder, list folder content, ...). Therefor I'm sure the authentication of the GraphClient is set okay.

What am I doing wrong? Can anyone help, please?

Stefan

1 Answers1

0

Apparently it has to do with the TLS settings. Inserting

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls Or System.Net.SecurityProtocolType.Tls11 Or System.Net.SecurityProtocolType.Tls12

at the top of the function resolved the issue.