New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Large file upload task #94
Conversation
…es to separate folder in spec\n 3. Add tests for LargeFileUploadUtil\n 3.Clean browserfiy action
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Customers will love this feature.
lib/src/LargeFileUploadTask.d.ts
Outdated
@@ -0,0 +1,47 @@ | |||
/// <reference types="node" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add jsdoc comments for interfaces, classes, and members. This should be generated from proper comments in the typescript.
lib/src/LargeFileUploadUtil.d.ts
Outdated
@@ -0,0 +1 @@ | |||
export declare const getValidRangeSize: (rangeSize?: number) => number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add js doc comments. This applies to all .d.ts
src/LargeFileUploadUtil.ts
Outdated
} | ||
|
||
export const getValidRangeSize = (rangeSize: number = DEFAULT_FILE_SIZE): number => { | ||
const sixtyMB = 60 * 1024 * 1024; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the significance of 60MB? Please add a comment about why this size is not arbitrary.
src/LargeFileUploadTask.ts
Outdated
// This method should be called to create an LargeFileUploadTask | ||
// To create this uploadTask in node user has to provide the file in the NodeFile format | ||
|
||
// retuns the instance of LargeFileUploadTask by making request to the sessionCreationUrl that is provided |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: typo 'retuns' becomes 'returns'
src/LargeFileUploadTask.ts
Outdated
} | ||
} | ||
|
||
// Delets the upload current upload task in the server |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: 'Delets' becomes 'Deletes'. Actually, this should be a proper doc comment so that it is picked up for .d.ts
src/LargeFileUploadTask.ts
Outdated
return blob; | ||
} | ||
|
||
// Uploads the file by slicing and uploadin each slice in a sequential manner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: 'uploadin' becomes 'uploading'
src/LargeFileUploadTask.ts
Outdated
_fileObject: FileObject = <FileObject>{}; | ||
switch(file.constructor.name) { | ||
case "Blob": | ||
_fileObject.name = self.getRandomFileName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should enable customers to name the file they are creating when they submit it as a blob. Perhaps add a member to LargeFileUploadTaskOptions
named blobFileName
and change line 59 to be = (options.blobFileName !== undefined) ? options.blobFileName : self.getRandomFileName();
spec/tasks/LargeFileUploadTask.ts
Outdated
rangeSize: 327680 | ||
}; | ||
let uploadTask = new LargeFileUploadTask(getClient(), fileObj, uploadSession, options); | ||
it('Should return an exceptoion as trying to upload a slice after the session has expired', (done) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: 'exceptoionbecomes
exception`
spec/tasks/LargeFileUploadTask.ts
Outdated
done(); | ||
}); | ||
|
||
it('Should return next range as default(empty) range,this is for the upload task completed', (done) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: space needed 'range, this'
src/LargeFileUploadTask.ts
Outdated
while (true) { | ||
let nextRange = self.getNextRange(); | ||
if (nextRange.maxValue === -1) { | ||
throw new Error("Invalid session: Uploading completed"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also aplies to line 181. Would it make sense to create the Error, and then give it a descriptive name so that customers can inspect the error.name and handle it? The error message should give some info on what happed advice on how the error can be handled.
This reverts commit a72448b.
…nts, Update error message and add name
@MIchaelMainer Made the changes that you are requested... |
src/LargeFileUploadTask.ts
Outdated
|
||
/** | ||
* @async | ||
* Resume the upload session and continue uploading the file from the place where it left |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resume the upload session and continue uploading the file from the last sent range.
src/LargeFileUploadTask.ts
Outdated
} | ||
|
||
/** | ||
* To update the exipiration date and the next range |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: expiration
src/LargeFileUploadTask.ts
Outdated
* @async | ||
* Creates a LargeFilUploadTask | ||
* @param client - The GraphClient instance | ||
* @param file - File representated as Blob, File or NodeFile object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change 'NodeFile' to 'Buffer'
src/LargeFileUploadTask.ts
Outdated
/** | ||
* @static | ||
* @async | ||
* Creates a LargeFilUploadTask |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change LargeFilUploadTask to LargeFileUploadTask
src/LargeFileUploadTask.ts
Outdated
case "File": | ||
let _file = <File>file; | ||
_fileObject.content = _file; | ||
_fileObject.name = _fileObject.name = (options.fileName !== undefined) ? options.fileName : _file.name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra '_fileObject.name =' or is this something I don't understand?
Can _file.name ever be undefined? If so, we should use the random name as a last resort.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is extra.!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can _file.name ever be undefined? If so, we should use the random name as a last resort.
_file.name will never be undefined.
src/LargeFileUploadTask.ts
Outdated
|
||
/** | ||
* User Options to create the upload task | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider this comment applicable to all of the files in this PR. Let's add doc comments to all of these types and members. These are all intended to be used by customers so let's make it easier for them to use them. Our .d.ts should be picking these up as well. I'm not sure how we go from .ts to .d.ts. Is there a tool for that?
/**
- Interface used to define options when creating an upload task.
- @interface
- @Property {string} sessionRequestUrl - The default values for parties.
- @Property {string} fileName - Optional. Specifies the file name of the file to upload. A file name will be created for you if you do not specify a value.
- @Property {number} rangeSize - Optional. Specifies the range chunk size. The default value of ??? is used if a value is not specified.
- @Property {number} maxTries - Optional. Specifies the ??? The default value of ??? is used if a value is not specified.
*/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, will define interface in this format.
Typescript compiling does that, when we do compile .ts files using typescript compiler, it generates .js, .d.ts and .js.map files
will investigate and make the compiler take comments from .ts to .d.ts if possible.
2. Pull request changes This reverts commit a72448b.
@MIchaelMainer
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please discuss the sesssionURL in Option and verify try catch mechanism while making upload call.
Changes look good.
.gitignore
Outdated
spec/secrets.ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not required, remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
…OneDriveLargeFileUploadTask, write corresponding unit tests
de10426
@darrelmiller @deepak2016 Done changes related to extending LargeFileUploadTask to OneDriveLargeFileUploadTask. |
@@ -0,0 +1 @@ | |||
export const AccessToken = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commenting done..!!
import { assert } from "chai"; | ||
import { OneDriveLargeFileUploadTask } from "../../lib/src/OneDriveLargeFileUploadTask"; | ||
|
||
declare const describe, it; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed...
declare
is used to tell TypeScript that the variable has been created elsewhere. If you use declare, nothing is added to the JavaScript that is generated - it is simply a hint to the compiler.
For example, if you use an external script that defines var externalModule, you would use declare var externalModule to hint to the TypeScript compiler that externalModule has already been set up
import { assert } from "chai"; | ||
import * as OneDriveLargeFileUploadTaskUtil from "../../lib/src/OneDriveLargeFileUploadTaskUtil"; | ||
|
||
declare const describe, it; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
spec/types/OneNote.ts
Outdated
@@ -1,6 +1,6 @@ | |||
import { assert } from 'chai' | |||
|
|||
import { getClient, randomString } from "./test-helper" | |||
import { getClient, randomString } from "../test-helper" | |||
import { Notebook, OnenoteSection, OnenotePage } from '@microsoft/microsoft-graph-types-beta' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls check if we need to run test against beta or v1.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These models are now available in v1.0 so have changed it to use v1.0
Large file upload task
In uncertain network connectivity areas uploading a large file would take multiple attempts to get it done. In case of larger files, it would take even more attempts to achieve or even impossible. Large file upload task helps in uploading large files effortlessly.
Implementation is done with the reference of this onedrive's resumable upload.
To create session and start upload:
With
async
/await
syntactic sugar in ECMAScript 2017We can just resume the broken upload:
Lets consider some break down happens in the middle of the uploading, with the uploadTask object in hand resuming comes easy.
Even you can control the whole upload process:
Just create the upload task, and play with it by using sliceFile and uploadSlice methods