KoenZomers / OneDriveAPI

API in .NET Framework 4.8.0, .NET Core 3.1 and .NET 6.0 to communicate with OneDrive Personal and OneDrive for Business
Eclipse Public License 1.0
109 stars 34 forks source link

Uploading to the app (special) folder #7

Closed jculverwell closed 6 years ago

jculverwell commented 6 years ago

Thank you kindly for a great repo, the authentication using a refresh token is so much nicer than the official OneDrive SDK.

I am currently stuck on how to upload to the App folder as described here https://docs.microsoft.com/en-us/onedrive/developer/rest-api/concepts/special-folders-appfolder and here https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/drive_get_specialfolder

I am using the UploadFileAs method but this is failing.

public virtual async Task<OneDriveItem> UploadFileAs(string filePath, string fileName, string oneDriveFolder)
        {
            var oneDriveItem = await GetItem(oneDriveFolder);
            return await UploadFileAs(filePath, fileName, oneDriveItem);
        }

Looking at the code I think the issue is that GetItem function uses 'drive/root:/' whereas 'special folders use '/drive/special/'. For example the app folder is '/drive/special/approot'.

public virtual async Task<OneDriveItem> GetItem(string path)
        {
            return await GetData<OneDriveItem>(string.Concat("drive/root:/", path));
        }

Thinking out aloud I think one fix could be something like below with basically attempts to not not prefix special paths with drive root.

public virtual async Task<OneDriveItem> GetItem(string path)
        {
            var newpath = path.Contains("drive/special") ? path : string.Concat("drive/root:/", path);
            return await GetData<OneDriveItem>(newpath);
        }

Actually it would probably be better to use StartsWith as below:

public virtual async Task<OneDriveItem> GetItem(string path)
        {
            var newpath = path.StartsWith("drive/special") ? path : string.Concat("drive/root:/", path);
            return await GetData<OneDriveItem>(newpath);
        }
jculverwell commented 6 years ago

Hi, just wondering if you had any thoughts regarding 'special folders'. Cheers

KoenZomers commented 6 years ago

Hi @jculverwell, I've just released v2.0.3.0 of the API in which commands have been added to work with AppFolders. I've also updated the demo application to provide samples of how to apply every possible operation to AppFolders through these new APIs.

jculverwell commented 6 years ago

Thank you, really appreciate this. I'm going to update and test next week. Thanks again

KoenZomers commented 6 years ago

Haven't heard back from you @jculverwell. I'm going to assume the added functionality works now. If not, feel free to reopen this topic.