I am using the following to allow a user to upload a profile photo with react-dropzone:
const FILE_FIELD_NAME = 'files';
const renderDropzoneInput = (field) => {
const files = field.input.value;
let dropzoneRef;
return (
<div>
<Dropzone
name={field.name}
onDrop={( filesToUpload, e ) => field.input.onChange(filesToUpload)}
ref={(node) => { dropzoneRef = node; }}
accept="image/jpeg, image/png"
maxSize={5242880}
>
{({ isDragActive, isDragReject, acceptedFiles, rejectedFiles }) => {
if (isDragActive) {
return "This file is authorized";
}
if (isDragReject) {
return "This file is not authorized";
}
return acceptedFiles.length || rejectedFiles.length
? `Accepted ${acceptedFiles.length}, rejected ${rejectedFiles.length} files`
: "Try dropping some files.";
}}
</Dropzone>
<button type="button" onClick={() => { dropzoneRef.open() }}>Open File Dialog</button>
{field.meta.touched &&
field.meta.error &&
<span className="error">{field.meta.error}</span>}
{
files && Array.isArray(files) && (
<ul>
{ files.map((file, i) =>
<li key={i}>
<img key={i} style={{width: 50, height: 50}} src={file.preview} alt="preview" />
{file.name}
</li>
)}
</ul>
)}
</div>
);
}
... inside my redux-form:
<div>
<label htmlFor={FILE_FIELD_NAME}>Files</label>
<Field
name={FILE_FIELD_NAME}
component={renderDropzoneInput}
/>
</div>
React-dropzone is currently respecting the maxSize, where it rejects files that are over 5megs. The problem is react-dropzone is not telling the user the file is too big.
How can I update the above to tell the user if the file exceeds the maxSize allowed?