Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/tasks/OneDriveLargeFileUploadTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export interface OneDriveLargeFileUploadOptions {
rangeSize?: number;
conflictBehavior?: string;
uploadEventHandlers?: UploadEventHandlers;
/// <summary>
/// Default upload session url is : "/me/drive/root:/{file-path}:/createUploadSession"
/// Set this property to override the default upload session url. Example: "/me/drive/special/{name}"
/// </summary>
uploadSessionURL?: string;
}

/**
Expand Down Expand Up @@ -161,7 +166,7 @@ export class OneDriveLargeFileUploadTask<T> extends LargeFileUploadTask<T> {
if (!client || !fileObject || !options) {
throw new GraphClientError("Please provide the Graph client instance, FileObject interface implementation and OneDriveLargeFileUploadOptions value");
}
const requestUrl = OneDriveLargeFileUploadTask.constructCreateSessionUrl(options.fileName, options.path);
const requestUrl = options?.uploadSessionURL ? options.uploadSessionURL: OneDriveLargeFileUploadTask.constructCreateSessionUrl(options.fileName, options.path);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the optional chaining of options here is not needed as line 166 validates that options has a value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the optional

const uploadSessionPayload: OneDriveFileUploadSessionPayLoad = {
fileName: options.fileName,
fileDescription: options.fileDescription,
Expand Down
13 changes: 13 additions & 0 deletions test/development/workload/largeFileUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,17 @@ describe("LargeFileUpload", () => {
const response = await uploadTask.upload();
assert.isDefined(response.responseBody["id"]);
}).timeout(30 * 1000);

it("Test OneDrive File Upload to custom url", async () => {
const options: OneDriveLargeFileUploadOptions = {
path: "/Documents",
fileName,
rangeSize: 1024 * 1024,
uploadSessionURL: `https://graph.microsoft.com/v1.0/me/drive/special/approot:/sampleTest/${fileName}:/createUploadSession`,
};
const file = fs.readFileSync(`./test/sample_files/${fileName}`);
const uploadTask = await OneDriveLargeFileUploadTask.create(client, file, options);
const response = await uploadTask.upload();
assert.isDefined(response.responseBody["id"]);
}).timeout(30 * 1000);
});