Skip to content

Commit

Permalink
Add minimum chunk size requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverwoodings committed Mar 31, 2016
1 parent 230f265 commit f86cdf6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/Upload.js
Expand Up @@ -14,12 +14,15 @@ import {
} from './errors'
import * as errors from './errors'

const MIN_CHUNK_SIZE = 262144
const DEFAULT_CHUNK_SIZE = 29999872 // 30MB (to nearest 256)

export default class Upload {
static errors = errors;

constructor (args) {
constructor (args, allowSmallChunks) {
var opts = {
chunkSize: 29999872, // 30MB (to nearest 256)
chunkSize: DEFAULT_CHUNK_SIZE,
storage: window.localStorage,
contentType: 'text/plain',
onChunkUpload: () => {},
Expand All @@ -29,7 +32,7 @@ export default class Upload {
...args
}

if (opts.chunkSize % 256 !== 0) {
if (opts.chunkSize % 256 !== 0 || (opts.chunkSize < MIN_CHUNK_SIZE && !allowSmallChunks) {
throw new InvalidChunkSizeError(opts.chunkSize)
}

Expand Down
2 changes: 1 addition & 1 deletion src/errors.js
Expand Up @@ -45,6 +45,6 @@ export class UploadIncompleteError extends ExtendableError {

export class InvalidChunkSizeError extends ExtendableError {
constructor (chunkSize) {
super(`Invalid chunk size ${chunkSize}, must be a multiple of 256`)
super(`Invalid chunk size ${chunkSize}, must be a multiple of 256 and be 262144 or greater`)
}
}
2 changes: 1 addition & 1 deletion test/functional-tests.js
Expand Up @@ -23,7 +23,7 @@ describe('Functional', () => {
url: url || '/file',
chunkSize: 256,
file: makeFile(file)
})
}, true)
await upload.start()
requests = getRequests()
return upload
Expand Down

0 comments on commit f86cdf6

Please sign in to comment.