-
Notifications
You must be signed in to change notification settings - Fork 252
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
Unable to upload a file whose name contains a URL-encoded slash character #2565
Comments
Thanks for raising this @mfeingol I believe this is related to #2541 as the name in the url should not need to be encoded. Any chance it works for you if you change the code to string name = "A/B+C D.zip"; // remove an encoding
Microsoft.Graph.Drives.Item.Items.Item.CreateUploadSession.CreateUploadSessionPostRequestBody body = new()
{
Item = new() { Name = name }
};
UploadSession upload = await graph.Drives[driveId].Items[folderId].ItemWithPath(name).CreateUploadSession.PostAsync(body, cancellationToken: cancellationToken); |
I tried uploading the following file name: Same Microsoft.Graph.Models.ODataErrors.ODataError exception - "Name specified in the path doesn't match the name specified in the request body."
But either way, if I'm specifying a valid string for a file name, encoded or not, that string should reach the OneDrive filesystem untouched and shouldn't be decoded anywhere along the way. |
Are you able to make a successful request on the graph explorer? |
I'm not sure how to upload a file from the Graph Explorer. I just see a text field for the PUT body; is there a way to provide file contents in there?
If I don't specify the Name property on the item, the upload succeeds but my url-encoded name is cracked and mayhem ensues. E.g. a url-encoded |
Just to confirm. Are you able to specify this in the body but not in the path? |
@andrueastman: I'm not sure how to do that programmatically. See above for the code I'm using. |
@mfeingol Taking a look at the one drive documentation, it looks like the API won't accept Any chance you can confirm if it's possible to make the request directly using the rest API? |
@andrueastman: the filename I'm providing is url-encoded. There is no
I absolutely can, if you can give me a hint on how to do this correctly. E.g. some C# code I can run? |
Any chance you can try using a raw requests with curl, Postman etc...?
What I mean here is that the API won't accept the characters as part of the file name even if they are url encoded. The API doesn't allow them and will throw an error for them... |
If you can give me an example REST request, I can do that. I'm not super familiar with the OD API. Reading that documentation you linked, I see no prohibition on url-encoding any character, even slashes or backslashes. Can you quote the specific language you're referring to? |
I captured a REST request using Fiddler and was able to reproduce the createUploadSession in a tool (Imsomnia). With no % in the file name and in the body, the request returns 200. With a % in the file name and in the body, the request returns 400. With a % in the file name and an empty body, the request returns 200, but uploading content results in the server side interpreting the %2F as a directory separator (!) Conclusion: the server side is kind of broken here. However... I'm able to create a file named a2%fb.text in my OneDrive folder. So ... how do I do that programmatically, if the obvious answer (escaping) doesn't work? |
A gentle ping on this question. What is the path forward here? |
Describe the bug
For reasons of my own, I'm trying to upload a file with the following name: A%2FB%2BC+D.zip. This is a URL-encoded form of the string "A/B+C D.zip"
With version 4.54.0 I get a new directory named A and a file inside that directory named B+C+D.zip. This is obviously incorrect behavior.
With version 5.56.0, I get the following Microsoft.Graph.Models.ODataErrors.ODataError exception when calling
CreateUploadSession
:This too is incorrect behavior.
Update: if my filename contains an encoded + (i.e. "%2B") that also causes
CreateUploadSession
to throw the same exception. Clearly something is attempting to decode the name improperly.Expected behavior
I'd expect the file to be uploaded with precisely the specified name, with no alterations performed by the underlying SDK or server side. None of the characters in the name are illegal, to the best of my understanding.
How to reproduce
5.56.0 code:
SDK Version
5.56.0
Latest version known to work for scenario above?
No response
Known Workarounds
No response
Debug output
No response
Configuration
Windows 11, x64, probably not specific to this configuration.
Other information
No response
The text was updated successfully, but these errors were encountered: