fix #152, puts a limit on the local file size
This commit is contained in:
parent
61925b67e4
commit
315e83c593
1 changed files with 4 additions and 3 deletions
|
@ -4,6 +4,7 @@ const textFileRegex = /(text\/|application\/json)/;
|
||||||
|
|
||||||
const s3BucketHttps = `https://s3-us-west-2.amazonaws.com/${process.env.S3_BUCKET}/`;
|
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 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 = {}) {
|
function localIntercept(file, options = {}) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
@ -34,7 +35,7 @@ export function dropzoneAcceptCallback(file, done) {
|
||||||
// for text files and small files
|
// for text files and small files
|
||||||
// check mime type
|
// check mime type
|
||||||
// if text, local interceptor
|
// if text, local interceptor
|
||||||
if (file.type.match(textFileRegex)) {
|
if (file.type.match(textFileRegex) && file.size < MAX_LOCAL_FILE_SIZE) {
|
||||||
localIntercept(file).then(result => {
|
localIntercept(file).then(result => {
|
||||||
file.content = result; // eslint-disable-line
|
file.content = result; // eslint-disable-line
|
||||||
done('Uploading plaintext file locally.');
|
done('Uploading plaintext file locally.');
|
||||||
|
@ -74,7 +75,7 @@ export function dropzoneAcceptCallback(file, done) {
|
||||||
|
|
||||||
export function dropzoneSendingCallback(file, xhr, formData) {
|
export function dropzoneSendingCallback(file, xhr, formData) {
|
||||||
return () => {
|
return () => {
|
||||||
if (!file.type.match(textFileRegex)) {
|
if (!file.type.match(textFileRegex) || file.size >= MAX_LOCAL_FILE_SIZE) {
|
||||||
Object.keys(file.postData).forEach(key => {
|
Object.keys(file.postData).forEach(key => {
|
||||||
formData.append(key, file.postData[key]);
|
formData.append(key, file.postData[key]);
|
||||||
});
|
});
|
||||||
|
@ -87,7 +88,7 @@ export function dropzoneSendingCallback(file, xhr, formData) {
|
||||||
|
|
||||||
export function dropzoneCompleteCallback(file) {
|
export function dropzoneCompleteCallback(file) {
|
||||||
return (dispatch, getState) => { // eslint-disable-line
|
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="';
|
let inputHidden = '<input type="hidden" name="attachments[]" value="';
|
||||||
const json = {
|
const json = {
|
||||||
url: `${s3BucketHttps}${file.postData.key}`,
|
url: `${s3BucketHttps}${file.postData.key}`,
|
||||||
|
|
Loading…
Reference in a new issue