Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidRequest Error when using UploadSession to upload files to OneDrive #2599

Closed
lavinir opened this issue Jul 28, 2024 · 7 comments
Closed
Labels

Comments

@lavinir
Copy link

lavinir commented Jul 28, 2024

Describe the bug

I am trying to upload files to the special App Folder in OneDrive. The code runs on multiple machines but some of them are getting errors attempting to upload files (each machine is using a different OneDrive account).

The Error being thrown is:

Error uploading backup: Microsoft.Graph.Models.ODataErrors.ODataError: Invalid request
at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.ThrowIfFailedResponse(HttpResponseMessage response, Dictionary2 errorMapping, Activity activityForAttributes, CancellationToken cancellationToken) at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory1 factory, Dictionary2 errorMapping, CancellationToken cancellationToken) at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory1 factory, Dictionary2 errorMapping, CancellationToken cancellationToken) at Microsoft.Graph.Drives.Item.Items.Item.CreateUploadSession.CreateUploadSessionRequestBuilder.PostAsync(CreateUploadSessionPostRequestBody body, Action1 requestConfiguration, CancellationToken cancellationToken)

No additional data indicating why the request is invalid or what might be causing the error.

Expected behavior

The upload session is created successfully and file upload goes through. (Or an appropriate error message explaining what's wrong with the request comes back)

How to reproduce

The code I am using to create the session:

var driveItem = await _userClient.Me.Drive.GetAsync();
            var appFolder = await _userClient.Drives[driveItem.Id].Special["approot"].GetAsync();

            var uploadSession = await _userClient.Drives[driveItem?.Id]
                .Items[appFolder.Id]
                .ItemWithPath(sanitizedDestinationFileName)
                .CreateUploadSession
                .PostAsync(new DriveUpload.CreateUploadSessionPostRequestBody()
                {
                    Item = new DriveItemUploadableProperties
                    {
                        Description = description
                    }
                });

SDK Version

5.38.0

Latest version known to work for scenario above?

No response

Known Workarounds

None - Works in some instances and fails in others.
The things that are different in each machine:

  1. OneDrive Account
  2. The Description in DriveItemUploadableProperties

Debug output

Click to expand log ``` Error uploading backup: Microsoft.Graph.Models.ODataErrors.ODataError: Invalid request at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.ThrowIfFailedResponse(HttpResponseMessage response, Dictionary2 errorMapping, Activity activityForAttributes, CancellationToken cancellationToken) at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory1 factory, Dictionary2 errorMapping, CancellationToken cancellationToken) at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory1 factory, Dictionary2 errorMapping, CancellationToken cancellationToken) at Microsoft.Graph.Drives.Item.Items.Item.CreateUploadSession.CreateUploadSessionRequestBuilder.PostAsync(CreateUploadSessionPostRequestBody body, Action1 requestConfiguration, CancellationToken cancellationToken) ```

Configuration

Mix of architectures (x64, ARM64, ARM)

Other information

No response

@lavinir lavinir added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Jul 28, 2024
@andrueastman
Copy link
Member

Thanks for raising this @lavinir

Any chance you can share what is being done to sanitize the name in the sanitizedDestinationFileName variable? Do you perform any url encoding/decoding?

@andrueastman andrueastman added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Jul 29, 2024
@lavinir
Copy link
Author

lavinir commented Jul 30, 2024

Hi @andrueastman,

Sure, this just strips the suffix and then removes illegal chars from the string using this logic:

            if (string.IsNullOrEmpty(input))
            {
                return input; 
            }

            char[] illegalChars = { '*', ':', '<', '>', '?', '/', '\\', '|' };

            string sanitizedString = new string(input.Select(c => illegalChars.Contains(c) ? '_' : c).ToArray());

            return sanitizedString;

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Jul 30, 2024
@andrueastman
Copy link
Member

@andrueastman andrueastman added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed Needs: Attention 👋 labels Aug 5, 2024
@lavinir
Copy link
Author

lavinir commented Aug 5, 2024

Thanks @andrueastman .
I will try to get a sample file name that is failing. Are you sure this is something that should be related to the file name ?
Is it possible the Description could also impact this ?

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Aug 5, 2024
@lavinir
Copy link
Author

lavinir commented Aug 14, 2024

Here is an example of a file name: "hass_backup_2024-08-05-12-57.tar"
@andrueastman

@andrueastman
Copy link
Member

Thanks for the extra information here @lavinir
The file name here does not look to have an issue here. Any chance you can try to capture all the properties of error details by following the guidance at https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/docs/errors.md#handling-errors-in-the-microsoft-graph-net-client-library?

Is it possible the Description could also impact this ?

Are you able to confirm if the description is very long or with special characters in this scenario?

@lavinir
Copy link
Author

lavinir commented Sep 4, 2024

I apologize @andrueastman , Did not get this notification. No, the description should not have any special chars or be very long.
The guidance link above seems broken - getting a 404 on that link.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close Status: No recent activity labels Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants