Skip to content

Commit 118f97b

Browse files
Added custom options sample for large file upload
1 parent 5bbcc43 commit 118f97b

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

docs/tasks/LargeFileUploadTask.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async function largeFileUpload(client, file) {
3939
const response = await uploadTask.upload();
4040
return response;
4141
} catch (err) {
42-
console.log(err);
42+
throw err;
4343
}
4444
}
4545
```
@@ -59,7 +59,7 @@ function uploadFile() {
5959
console.log("File Uploaded Successfully.!!");
6060
})
6161
.catch((error) => {
62-
console.error(error);
62+
throw err;
6363
});
6464
});
6565
}
@@ -97,3 +97,35 @@ let range = uploadTask.getNextRange();
9797
let slicedFile = uploadTask.sliceFile(range);
9898
uploadTask.uploadSlice(slicedFile, range, uploadTask.file.size);
9999
```
100+
101+
## Uploading with custom options
102+
103+
_You can pass in the customized options using LargeFileUploadTask_
104+
105+
```typescript
106+
async function largeFileUpload(client, file) {
107+
const filename = file.name;
108+
const driveId = "<YOUR_DRIVE_ID>";
109+
const path = "LOCATION_TO_STORE_FILE";
110+
try {
111+
const requestUrl = `/drives/${driveId}/root:${path}/${fileName}:/createUploadSession`;
112+
const payload = {
113+
item: {
114+
"@microsoft.graph.conflictBehavior": "fail",
115+
name: fileName,
116+
},
117+
};
118+
const fileObject = {
119+
size: file.size,
120+
content: file,
121+
name: fileName,
122+
};
123+
const uploadSession = await LargeFileUploadTask.createUploadSession(client, requestUrl, payload);
124+
const uploadTask = await new LargeFileUploadTask(client, fileObject, uploadSession);
125+
const response = await uploadTask.upload();
126+
return response;
127+
} catch (err) {
128+
throw err;
129+
}
130+
}
131+
```

src/tasks/LargeFileUploadTask.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export class LargeFileUploadTask {
129129
* @param {LargeFileUploadTaskOptions} options - The upload task options
130130
* @returns An instance of LargeFileUploadTask
131131
*/
132-
public constructor(client: Client, file: FileObject, uploadSession: LargeFileUploadSession, options: LargeFileUploadTaskOptions) {
132+
public constructor(client: Client, file: FileObject, uploadSession: LargeFileUploadSession, options: LargeFileUploadTaskOptions = {}) {
133133
this.client = client;
134134
this.file = file;
135135
if (options.rangeSize === undefined) {

0 commit comments

Comments
 (0)