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

Uploading files using OneDriveLargeFileUploadTask with only the Files.ReadWrite.AppFolder permission is not possible #917

Closed
5 of 6 tasks
chjohan opened this issue Aug 9, 2022 · 7 comments · Fixed by #1010
Assignees
Labels

Comments

@chjohan
Copy link

chjohan commented Aug 9, 2022

Bug Report

Prerequisites

  • Can you reproduce the problem?
  • Are you running the latest version?
  • Are you reporting to the correct repository?
  • Did you perform a cursory search?

For more information, see the CONTRIBUTING guide.

Description

The name of the "Apps"-folder which is used when using the "Files.ReadWrite.AppFolder" permission is determined from the users' language. For english users the folder is named "Apps", bur for norwegian users the folder is named "Apper". As a consuquence it is very inpractical uploading files with "OneDriveLargeFileUploadTask", which requires you to supply the upload path when creating an upload session because, there is no way to get the name of the "Apps"-folder using only the "Files.ReadWrite.AppFolder"-permission.
For this you have to enable the Files.Read permission.

Console Errors: Not applicable.

Screenshots: [If applicable, add screenshots to help explain your problem]

Steps to Reproduce

  1. Create an Azure AD appregistration with the following delegated permissions:
  • User.Read
  • Files.ReadWrite.AppFolder
  • offline_access
  1. Grant permissions to the app from a test user
  2. Upload a large file
const uploadTask = await OneDriveLargeFileUploadTask.create(
	graphClient, fileContent, {
	path: "/Apps/MyApp",
	fileName: fileName,
		rangeSize: 4 * 1024 * 1024, // must be a multiple of 320 KiB
		conflictBehavior: "fail"
	}
);
const response = await uploadTask.upload();

Expected behavior: I either should be able to upload the file without knowing the name of the users "Apps" folder, or be allowed to get the name of the "Apps" folder, with the "Files.ReadWrite.AppFolder" permission, or be able to provide a path using the special/approot path format.

Actual behavior: "Apps"-folder does not exist when the target user has a different language than english, resulting in a 404.

Usage Information

Request ID - Value of the requestId field if you are receiving a Graph API error response

SDK Version - "@microsoft/microsoft-graph-client": "^3.0.2",

  • Node (Check, if using Node version of SDK)

Node Version - v12

  • Browser (Check, if using Browser version of SDK)

Browser Name - Not applicable. Server side.

Version - [The version of the browser you are using]

@ghost ghost added the ToTriage label Aug 9, 2022
@nikithauc nikithauc self-assigned this Aug 9, 2022
@ghost ghost removed the ToTriage label Aug 9, 2022
@nikithauc
Copy link
Contributor

@chjohan This is an interesting use case that you have brought forward. Thank you!

@nikithauc
Copy link
Contributor

@chjohan Are you using a personal authentication token or a business/org account? That is, OneDrive for consumer or OneDrive for business?

@chjohan
Copy link
Author

chjohan commented Aug 11, 2022

@chjohan Are you using a personal authentication token or a business/org account? That is, OneDrive for consumer or OneDrive for business?

@nikithauc Personal authentication token. OneDrive for consumer. I have not tested with a business/org account.

@kevklam
Copy link

kevklam commented Aug 12, 2022

Hi @chjohan ,
I am from the API team (not the SDK team) - the functionality you want is available by combining 'special folder' addressing with the 'resumable upload' API:
https://docs.microsoft.com/en-us/graph/api/drive-get-specialfolder?view=graph-rest-1.0&tabs=http
https://docs.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0

The combined request would look something like:
POST https://graph.microsoft.com/v1.0/me/drive/special/approot:/somePath/fileToCreate.txt:/createUploadSession

I am not very familiar with the SDK code, but looking at OneDriveLargeFileUploadTask.create(), it looks like it hardcodes the API path to something like /me/drive/root:/{file-path}:/createUploadSession, which will prevent you from using the 'special folder' addressing method.

It seems like to work around this you'd need to replicate the logic in create() and createTaskWithFileObject(), but modify createTaskWithFileObject to use your own custom request URI instead of calling constructCreateSessionUrl().

@nikithauc - it would probably be helpful to include a way in the SDK to compose your own request URI here.

Thanks,
Kevin

@nikithauc
Copy link
Contributor

Thank you so much for your help @kevklam!

@chjohan You can use the LargeFileTaskUpload instead which will help you to upload the file to OneDrive and you can customize the path.
https://github.com/microsoftgraph/msgraph-sdk-javascript/blob/dev/docs/tasks/LargeFileUploadTask.md.

Please let me know if you have more questions.

@ghost
Copy link

ghost commented Aug 17, 2022

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@nikithauc
Copy link
Contributor

Fix released in v3.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants