Skip to content

Commit aaf142e

Browse files
hasridhazengin
andauthored
Update OneDriveLargeFileUploadTask.ts (#325)
* Update OneDriveLargeFileUploadTask.ts Trying to upload files with the '#' or '%' character in the filename ends with network errors of the form - 400 status response "The parameter item does not exist in method getByPath" Encoding the entire URL does not encode URL components correctly. When the SDK's client tries to encode these URL components in the parameters on the call to OneDriveLargeFileUploadTask.create, then the resultant file in OneDrive has the URL encoded filename (as opposed to the user-friendly/decoded filename). Therefore, fix the encoding in the SDK's URL components itself, directly. * Update OneDriveLargeFileUploadTask.ts Fix typo * Update src/tasks/OneDriveLargeFileUploadTask.ts Updated comment Co-authored-by: Mustafa Zengin <mzengin88@gmail.com> * Update OneDriveLargeFileUploadTask.ts Updated comment Co-authored-by: Mustafa Zengin <mzengin88@gmail.com>
1 parent ab824f7 commit aaf142e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/tasks/OneDriveLargeFileUploadTask.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ export class OneDriveLargeFileUploadTask extends LargeFileUploadTask {
5959
if (path[path.length - 1] !== "/") {
6060
path = `${path}/`;
6161
}
62-
return encodeURI(`/me/drive/root:${path}${fileName}:/createUploadSession`);
62+
// we choose to encode each component of the file path separately because when encoding full URI
63+
// with encodeURI, special characters like # or % in the file name doesn't get encoded as desired
64+
return `/me/drive/root:${path.split('/').map(p => encodeURIComponent(p)).join('/')}${encodeURIComponent(fileName)}:/createUploadSession`;
6365
}
6466

6567
/**

0 commit comments

Comments
 (0)