diff --git a/src/lib/api/upload/upload.ts b/src/lib/api/upload/upload.ts index 6ae39da9..7a8c5e0d 100644 --- a/src/lib/api/upload/upload.ts +++ b/src/lib/api/upload/upload.ts @@ -20,6 +20,7 @@ import { Session, Security } from '../../client'; import { S3Uploader } from './uploaders/s3'; import { FilestackError, FilestackErrorType } from './../../../filestack_error'; import { SanitizeOptions } from './../../utils'; +import { File as FsFile } from './file'; import { UploadOptions, StoreUploadOptions } from '../upload/types'; import { getFile, InputFile } from './file_tools'; @@ -34,7 +35,8 @@ export interface ProgressEvent { } const DEFAULT_PROGRESS_INTERVAL = 1000; - +const BIG_FILE_THRESHOLD = 50 * 1000 * 1000 * 1000 // 50GB +const BIG_FILE_PART_SIZE = 10 * 1024 * 1024; // 10MB const normalizeProgress = (current, last) => { current.totalBytes = Math.max(current.totalBytes, last.totalBytes); current.totalPercent = Math.max(current.totalPercent, last.totalPercent); @@ -195,6 +197,19 @@ export class Upload extends EventEmitter { this.uploader.setUploadTags(tags); } + /** + * Set upload part size + * + * @param {File} file + * @param {S3Uploader} uploader + * @memberof Upload + */ + private setPartSize(uploader : S3Uploader, file : FsFile ){ + if(file.size > BIG_FILE_THRESHOLD){ + uploader.setPartSize(BIG_FILE_PART_SIZE); + } + } + /** * Upload single file * @@ -206,6 +221,8 @@ export class Upload extends EventEmitter { const f = await getFile(input, this.sanitizerOptions); f.customName = this.overrideFileName; + this.setPartSize(this.uploader, f); + this.uploader.addFile(f); this.startProgressInterval(); @@ -237,6 +254,7 @@ export class Upload extends EventEmitter { const f = await getFile(input[i], this.sanitizerOptions); f.customName = this.overrideFileName; + this.setPartSize(this.uploader, f); this.uploader.addFile(f); }