Skip to content
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

Feature/big file upload #472

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/lib/api/upload/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down Expand Up @@ -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
*
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}

Expand Down