Repository navigation
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
Michael Mainer (MIchaelMainer)
left a comment
There was a problem hiding this comment.
👍 Customers will love this feature.
| @@ -0,0 +1,47 @@ | |||
| /// <reference types="node" /> | |||
There was a problem hiding this comment.
Add jsdoc comments for interfaces, classes, and members. This should be generated from proper comments in the typescript.
| @@ -0,0 +1 @@ | |||
| export declare const getValidRangeSize: (rangeSize?: number) => number; | |||
There was a problem hiding this comment.
Add js doc comments. This applies to all .d.ts
| } | ||
|
|
||
| export const getValidRangeSize = (rangeSize: number = DEFAULT_FILE_SIZE): number => { | ||
| const sixtyMB = 60 * 1024 * 1024; |
There was a problem hiding this comment.
What is the significance of 60MB? Please add a comment about why this size is not arbitrary.
| // 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.
Nit: typo 'retuns' becomes 'returns'
| } | ||
| } | ||
|
|
||
| // Delets the upload current upload task in the server |
There was a problem hiding this comment.
Nit: 'Delets' becomes 'Deletes'. Actually, this should be a proper doc comment so that it is picked up for .d.ts
| return blob; | ||
| } | ||
|
|
||
| // Uploads the file by slicing and uploadin each slice in a sequential manner |
There was a problem hiding this comment.
Nit: 'uploadin' becomes 'uploading'
| _fileObject: FileObject = <FileObject>{}; | ||
| switch(file.constructor.name) { | ||
| case "Blob": | ||
| _fileObject.name = self.getRandomFileName(); |
There was a problem hiding this comment.
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();
| 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.
Nit: 'exceptoionbecomesexception`
| 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.
Nit: space needed 'range, this'
| while (true) { | ||
| let nextRange = self.getNextRange(); | ||
| if (nextRange.maxValue === -1) { | ||
| throw new Error("Invalid session: Uploading completed"); |
There was a problem hiding this comment.
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
|
Michael Mainer (@MIchaelMainer) Made the changes that you are requested... |
|
|
||
| /** | ||
| * @async | ||
| * Resume the upload session and continue uploading the file from the place where it left |
There was a problem hiding this comment.
Resume the upload session and continue uploading the file from the last sent range.
| } | ||
|
|
||
| /** | ||
| * To update the exipiration date and the next range |
There was a problem hiding this comment.
nit: expiration
| * @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.
Change 'NodeFile' to 'Buffer'
| /** | ||
| * @static | ||
| * @async | ||
| * Creates a LargeFilUploadTask |
There was a problem hiding this comment.
Change LargeFilUploadTask to LargeFileUploadTask
| 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.
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.
That is extra.!
There was a problem hiding this comment.
Can _file.name ever be undefined? If so, we should use the random name as a last resort.
_file.name will never be undefined.
|
|
||
| /** | ||
| * User Options to create the upload task | ||
| */ |
There was a problem hiding this comment.
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.
- Mark Lilly (@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.
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.
|
Michael Mainer (@MIchaelMainer)
|
Deepak Agrawal (deepak2016)
left a comment
There was a problem hiding this comment.
Please discuss the sesssionURL in Option and verify try catch mechanism while making upload call.
Changes look good.
| spec/types/*.js | ||
| spec/types/*.d.ts | ||
| spec/types/*.js.map No newline at end of file | ||
| spec/secrets.ts |
There was a problem hiding this comment.
not required, remove.
There was a problem hiding this comment.
Removed.
…OneDriveLargeFileUploadTask, write corresponding unit tests
de10426
|
Darrel (@darrelmiller) Deepak Agrawal (@deepak2016) Done changes related to extending LargeFileUploadTask to OneDriveLargeFileUploadTask. |
| @@ -0,0 +1 @@ | |||
| export const AccessToken = ""; No newline at end of file | |||
There was a problem hiding this comment.
Commenting done..!!
| import { assert } from "chai"; | ||
| import { OneDriveLargeFileUploadTask } from "../../lib/src/OneDriveLargeFileUploadTask"; | ||
|
|
||
| declare const describe, it; |
There was a problem hiding this comment.
Needed...
declareis 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; |
|
|
||
| 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.
pls check if we need to run test against beta or v1.0
There was a problem hiding this comment.
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/awaitsyntactic 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