From 315e83c593df12adaa94de2d95183ad2e0c6af5e Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Tue, 25 Oct 2016 15:51:44 -0400 Subject: [PATCH] fix #152, puts a limit on the local file size --- client/modules/IDE/actions/uploader.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/modules/IDE/actions/uploader.js b/client/modules/IDE/actions/uploader.js index fa8229e8..fb7976dc 100644 --- a/client/modules/IDE/actions/uploader.js +++ b/client/modules/IDE/actions/uploader.js @@ -4,6 +4,7 @@ const textFileRegex = /(text\/|application\/json)/; const s3BucketHttps = `https://s3-us-west-2.amazonaws.com/${process.env.S3_BUCKET}/`; const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api'; +const MAX_LOCAL_FILE_SIZE = 80000; // bytes, aka 80 KB function localIntercept(file, options = {}) { return new Promise((resolve, reject) => { @@ -34,7 +35,7 @@ export function dropzoneAcceptCallback(file, done) { // for text files and small files // check mime type // if text, local interceptor - if (file.type.match(textFileRegex)) { + if (file.type.match(textFileRegex) && file.size < MAX_LOCAL_FILE_SIZE) { localIntercept(file).then(result => { file.content = result; // eslint-disable-line done('Uploading plaintext file locally.'); @@ -74,7 +75,7 @@ export function dropzoneAcceptCallback(file, done) { export function dropzoneSendingCallback(file, xhr, formData) { return () => { - if (!file.type.match(textFileRegex)) { + if (!file.type.match(textFileRegex) || file.size >= MAX_LOCAL_FILE_SIZE) { Object.keys(file.postData).forEach(key => { formData.append(key, file.postData[key]); }); @@ -87,7 +88,7 @@ export function dropzoneSendingCallback(file, xhr, formData) { export function dropzoneCompleteCallback(file) { return (dispatch, getState) => { // eslint-disable-line - if (!file.type.match(textFileRegex) && file.status !== 'error') { + if ((!file.type.match(textFileRegex) || file.size >= MAX_LOCAL_FILE_SIZE) && file.status !== 'error') { let inputHidden = '