Skip to content

Commit

Permalink
Support 'file description' in LargeFileUploadTask. (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
buptliuhs authored Dec 10, 2021
1 parent 5183690 commit f1fda65
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions samples/typescript/tasks/OneDriveLargeFileUploadTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { client } from "../clientInitialization/ClientWithOptions";
async function upload() {
const file = fs.createReadStream("./test.pdf");
const fileName = "FILENAME";
const fileDescription = "FILEDESCRIPTION";
const stats = fs.statSync(`./test.pdf`);
const totalSize = stats.size;

Expand All @@ -38,6 +39,7 @@ async function upload() {

const options: OneDriveLargeFileUploadOptions = {
fileName,
fileDescription,
conflictBehavior: "rename",
rangeSize: 1024 * 1024,
uploadEventHandlers,
Expand Down
6 changes: 6 additions & 0 deletions src/tasks/OneDriveLargeFileUploadTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ import { getValidRangeSize } from "./OneDriveLargeFileUploadTaskUtil";
* @interface
* Signature to define options when creating an upload task
* @property {string} fileName - Specifies the name of a file to be uploaded (with extension)
* @property {string} [fileDescription] - Specifies the description of the file to be uploaded
* @property {string} [path] - The path to which the file needs to be uploaded
* @property {number} [rangeSize] - Specifies the range chunk size
* @property {string} [conflictBehavior] - Conflict behaviour option
* @property {UploadEventHandlers} [uploadEventHandlers] - UploadEventHandlers attached to an upload task
*/
export interface OneDriveLargeFileUploadOptions {
fileName: string;
fileDescription?: string;
path?: string;
rangeSize?: number;
conflictBehavior?: string;
Expand All @@ -37,10 +39,12 @@ export interface OneDriveLargeFileUploadOptions {
* @interface
* Signature to define options when creating an upload task
* @property {string} fileName - Specifies the name of a file to be uploaded (with extension)
* @property {string} [fileDescription] - Specifies the description of the file to be uploaded
* @property {string} [conflictBehavior] - Conflict behaviour option
*/
interface OneDriveFileUploadSessionPayLoad {
fileName: string;
fileDescription?: string;
conflictBehavior?: string;
}

Expand Down Expand Up @@ -160,6 +164,7 @@ export class OneDriveLargeFileUploadTask<T> extends LargeFileUploadTask<T> {
const requestUrl = OneDriveLargeFileUploadTask.constructCreateSessionUrl(options.fileName, options.path);
const uploadSessionPayload: OneDriveFileUploadSessionPayLoad = {
fileName: options.fileName,
fileDescription: options.fileDescription,
conflictBehavior: options.conflictBehavior,
};
const session = await OneDriveLargeFileUploadTask.createUploadSession(client, requestUrl, uploadSessionPayload);
Expand All @@ -185,6 +190,7 @@ export class OneDriveLargeFileUploadTask<T> extends LargeFileUploadTask<T> {
item: {
"@microsoft.graph.conflictBehavior": payloadOptions?.conflictBehavior || "rename",
name: payloadOptions?.fileName,
description: payloadOptions?.fileDescription,
},
};
return super.createUploadSession(client, requestUrl, payload);
Expand Down

0 comments on commit f1fda65

Please sign in to comment.