fix #152, puts a limit on the local file size

This commit is contained in:
Cassie Tarakajian 2016-10-25 15:51:44 -04:00
parent 61925b67e4
commit 315e83c593

View file

@ -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 = '<input type="hidden" name="attachments[]" value="';
const json = {
url: `${s3BucketHttps}${file.postData.key}`,