Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions docs/tasks/LargeFileUploadTask.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const options: OneDriveLargeFileUploadOptions = {
fileName,
rangeSize: 1024 * 1024,
uploadEventHandlers,
uploadSessionURL: "optional_custom_uploadSessionURL" //if undefined defaults to "/me/drive/root:/{file-path}:/createUploadSession"
};
const readStream = fs.createReadStream(`./fileName`);
const fileObject = new StreamUpload(readStream, fileName, totalsize);
Expand Down
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);
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);
});