microsoftgraph / msgraph-sdk-serviceissues

Tracks service issues for follow up.
5 stars 0 forks source link

[Client bug]: "InternalServerError / Stream read failure" when put stream from HttpClient of size almost 4MB to OneDrive #62

Open sirmrowa opened 3 years ago

sirmrowa commented 3 years ago

When trying to upload a 4 193 997 bytes length file to OneDrive I get InternalServerError / Stream read failure. Stream to file is from HttpClient that its gets from another service. I prepare some code to show the problem.

class Program
    {
        static async Task Main(string[] args)
        {
            var client = CreateClient();
            var userId = await client.Users[UserEmail].Request().GetAsync();

            // Get file of size 4 193 997 bytes or more from http server
            var stream = await GetStreamFromHttpClientAsync();

            var driveItem = await client.Users[userId.Id]
                .Drive.Root.ItemWithPath("test.bin")
                .Content.Request()
                .PutAsync<DriveItem>(stream);
        }

        private static IGraphServiceClient CreateClient()
        {
            var confidentialClientApplication = ConfidentialClientApplicationBuilder
                .Create(ClientId)
                .WithTenantId(TenatntId)
                .WithClientSecret(ClientSecret)
                .Build();

            var authProvider = new ClientCredentialProvider(confidentialClientApplication);

            return new GraphServiceClient(authProvider);
        }

        private static async Task<Stream> GetStreamFromHttpClientAsync()
        {
            var httpClient = new HttpClient();
            var request = new HttpRequestMessage(HttpMethod.Get, "http://127.0.0.1:3000/file");
            // second parameter is mandatory to don't get all file to memory
            var response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);

            return await response.Content.ReadAsStreamAsync();
        }
    }

When a file is a one-byte length less then everything works OK. I notice that if the protocol is HTTPS then the border file size is smaller.

To Reproduce

  1. Put any file of size 4 193 997 bytes on HTTP server
  2. Adjust URL to file on HTTP server
  3. Run code
  4. See error

Expected behavior This file is 4MB less and should be uploaded to OneDrive without any error.

Client version 3.29

AB#8902

petrhollayms commented 5 months ago

Thank you for reporting this issue. This appears to be an issue or limitation with the service APIs. Unfortunately, as the Microsoft Graph SDK team, we do not have ownership of the APIs that are causing you issues. We invite you to create a question about the service API to Microsoft Q&A and tagged with one of the [microsoft-graph-*] tags, that way it will get routed to the appropriate team for them to triage:

https://aka.ms/msgraphsupport or directly https://aka.ms/askgraph

For now, we will close the issue on our side but feel free to open it in the relevant repository if you think the issue is specific to SDK. Please let us know if this helps!

Note: We will close this repository on April 19, 2024.